python - 我的python代码出现问题

标签 python if-statement syntax-error

anwser=str(input("Do you need a new phone? "))

if answer== "no":   
    print ("You are now finished. ")
else:    
    question1=str(input("Do you know what phone you want? ")
    if question1== "no":
        print("Research different phones and chose which pne you like best.")
    else:
        question2=str(input("Do you want to go on a contract? ")
        if question2== "no": 
             question3=str(input("Do you have enought money to pay full price for your phone? ")

怎么了?我该如何改善?它不断出现语法错误,我不知道为什么。

最佳答案

您在问题线上缺少右括号:

question1 = str(input("Do you know what phone you want? ")

应该:
question1 = str(input("Do you know what phone you want? "))

您也不需要将输入转换为字符串,因为 input() 已经为您做到了:

input([prompt])

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

关于python - 我的python代码出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33595790/

相关文章:

python - Python 中是否有某种虚拟数据库?

使用多个 if 语句的 javascript 表单验证

javascript - 为什么我的背景不会在点击十六进制颜色时发生变化?

php - PHP解析/语法错误;以及如何解决它们

python - Python无效语法...?

python - 有没有办法在引用原始列表的同时将列表元素转换为自变量?

Python np.delete 问题

Python:从列表动态生成属性

Python 从文件中删除用户选择的一行

python - 在 python 中保存来自 JSON 数据的许多文件文本