为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

梵蒂冈之花 2021-07-28 21:38:43
我今天正在写一些代码,只是一个小脚本,它最多占用三个字符串,并把它们弄乱,颠倒它们,并将它们按不同的顺序排列。当我尝试运行我的代码时,我收到一个无效的语法错误,但我真的不知道为什么。ammount = int(input("How many strings would you like to input? 1, 2 or 3?")# Getting user inputif 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"))
查看完整描述

2 回答

?
翻翻过去那场雪

TA贡献2065条经验 获得超14个赞

)转换为 int 后,您错过了关闭

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


查看完整回答
反对 回复 2021-08-03
?
隔江千里

TA贡献1906条经验 获得超10个赞

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


查看完整回答
反对 回复 2021-08-03
  • 2 回答
  • 0 关注
  • 132 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号