我今天正在编写一些代码,只是一个小脚本,它最多包含三个字符串并弄乱它们,将它们反转,然后按不同的顺序排列。当我尝试运行代码时,出现无效的语法错误,但我真的不知道为什么。
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"))
答案 0 :(得分:2)
转换为整数后,您缺少结尾)
ammount = int(input("How many strings would you like to input? 1, 2 or 3?"))
答案 1 :(得分:1)
您可能会在if语句上收到错误,因为您在)
语句之前的行末缺少结尾括号if ammount ==1:
。错误落在if语句上,因为python解释器认为您正在尝试将if语句放入强制转换为int函数的内部,并且不属于该函数