首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >即使该条件的“如果”部分为真,也只有其他部分正在执行。无论输入是什么,只有其他输入执行

即使该条件的“如果”部分为真,也只有其他部分正在执行。无论输入是什么,只有其他输入执行
EN

Stack Overflow用户
提问于 2020-06-06 08:20:33
回答 3查看 40关注 0票数 0

这里是我的代码

代码语言:javascript
复制
inputUSer=input('''
    Please Select The Mode you want to operate The script AS:
    1:  You selected-1 \n
    2:  You selected-2 \n
    3:  You selected-3\n
    4:  You selected-4 \n
''')

if inputUSer==1:
    print("You selected-1")


elif inputUSer==2:
    print("You selected-2")

elif inputUSer== 3:
    print("You selected-3")

elif inputUSer== 4:
    print("You selected-4")

else :
    print("OOPS! Seems like you entered the wrong Input")

我检查了所有的压痕,这是正确的。我对蟒蛇和Noob很陌生。请帮帮我..。谢谢..。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-06-06 08:22:25

input()的结果是一个str,它永远不等于1,2,3,4作为它们的ints,您需要转换输入

代码语言:javascript
复制
inputUSer = int(input('''
    Please Select The Mode you want to operate The script AS:
    1:  You selected-1 \n
    2:  You selected-2 \n
    3:  You selected-3\n
    4:  You selected-4 \n
'''))

或将所有if更改为比较str

代码语言:javascript
复制
if inputUSer == '1':
票数 2
EN

Stack Overflow用户

发布于 2020-06-06 08:24:19

将输入传递到int()

代码语言:javascript
复制
inputUSer=int(input('''
    Please Select The Mode you want to operate The script AS:
    1:  You selected-1 \n
    2:  You selected-2 \n
    3:  You selected-3\n
    4:  You selected-4 \n
'''))
票数 1
EN

Stack Overflow用户

发布于 2020-06-06 08:24:20

input的返回值是一个字符串。您可能希望使用int函数将其转换为整数。或者,您可以更改if条件,将inputUSer与字符串进行比较。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62229131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档