输入回应无法正常运作

时间:2019-11-13 01:54:29

标签: python

我是python的新手,我想知道为什么我的代码无法正常工作。

代码如下:

print("\n \n Would you like a phone case for your phone? \n \n We have a rubber case for 20 MYR and a carbon fiber case for 100 MYR.")

case = str(input("\n \n Do you want one?")).upper

while (case != "YES" and case != "NO"):
    print("\n Sorry, what do you mean?")
    case = str(input()).upper()

if (case) == ("YES"):
    case = 'yes'
    casetype = str(input("\n \n Which one would you like?")).upper
    if (casetype) == ("RUBBER CASE"):
        casetype = 'rubber case'
        money = money + 20
    if (casetype) == ("CARBON FIBER CASE"):
        casetype = 'carbon fiber case'
        money = money + 100

但是,当我回答是否要我回答案件时,我的回答是:“对不起,你是什么意思?”

2 个答案:

答案 0 :(得分:1)

拨打此行时:

case = str(input("\n \n Do you want one?")).upper

您缺少括号,无法将其转换为函数调用。试试:

case = str(input("\n \n Do you want one?")).upper()

然后您的比较就可以了。

答案 1 :(得分:0)

这些行需要进行函数调用:

case = str(input("\n \n Do you want one?")).upper
casetype = str(input("\n \n Which one would you like?")).upper

赞:

case = str(input("\n \n Do you want one?")).upper()
casetype = str(input("\n \n Which one would you like?")).upper()

否则,您将str.upper方法存储为变量