猿问

Python 告诉我我的 if 语句包含语法错误

我今天正在写一些代码,只是一个小脚本,它最多占用三个字符串,并把它们弄乱,颠倒它们,并将它们按不同的顺序排列。当我尝试运行我的代码时,我收到一个无效的语法错误,但我真的不知道为什么。


ammount = int(input("How many strings would you like to input? 1, 2 or 3?")

# Getting user input

if ammount == 1:

    input1 = str(input("Please enter the first string"))

elif ammount == 2:

    user_input_1 = str(input("Please enter the first string"))

    user_input_2 = str(input("Please enter the second string"))

elif ammount == 3:

    user_input_1 = str(input("Please enter the first string"))

    user_input_2 = str(input("Please enter the second string"))

    user_input_3 = str(input("Please enter the third string"))


梵蒂冈之花
浏览 133回答 2
2回答

翻翻过去那场雪

)转换为 int 后,您错过了关闭ammount = int(input("How many strings would you like to input? 1, 2 or 3?"))

隔江千里

您可能在 if 语句中收到错误消息,因为您)在if ammount ==1:语句之前的行尾缺少一个结束括号。错误落在 if 语句上,因为 python 解释器认为您试图将 if 语句放在转换为 int 函数的内部,而它不属于那里
随时随地看视频慕课网APP

相关分类

Python
我要回答