首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在if语句中使用Python输入时,Python输入无法正常工作

在if语句中使用Python输入时,Python输入无法正常工作
EN

Stack Overflow用户
提问于 2018-06-18 04:22:59
回答 1查看 35关注 0票数 1

我做了一个快速预算程序来确定买一件东西需要多长时间,但我遇到了一个问题。每当我尝试运行它时,一次性销售项目都不会添加到余额中。我的代码如下:

代码语言:javascript
复制
graphicsCard = 50
amdCpu = 80
itelCpu = 99
ram = 140
guitar = 199
case = 99
balance = 21
if (input('Has the graphics card been sold yet?').lower == "yes"):
    balance += graphicsCard
if (input('Has the AMD cpu been sold yet?').lower == "yes"):
    balance += amdCpu
if (input('Has the intel CPU been sold yet?').lower == "yes"):
    balance += intelCpu
if (input('Has the RAM been sold yet?').lower == "yes"):
    balance += ram
if (input('Has the Guitar been sold yet?').lower == "yes"):
    balance += guitar
if (input('Has the Case been sold yet?').lower == "yes"):
    balance += case

我在第一个if之后添加了一个else语句,以检测它是否正确地读取了我的“yes”答案,但它没有。

EN

回答 1

Stack Overflow用户

发布于 2018-06-18 04:31:22

您应该尝试使用.lower()

代码语言:javascript
复制
>>> myinput = input('Enter something: ')
Enter something: yes
>>> myinput.lower
<built-in method lower of str object at 0x7f79b2391068>
>>> myinput.lower()
'yes'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50900186

复制
相关文章

相似问题

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