阿洛, 我一直在尝试用python制作一个秒表/倒计时计时器,当我输入我的原始输入来选择什么类型的计时器(秒表或倒计时)时,当我输入时,它会将C(表示倒计时)转换为upcase,但当我输入S(表示秒表)时,它不会将它转换为upcase。我试过写几封不同的信,但也不管用。这是我的密码:
typeOfTimer = raw_input("What type of timer do you want? enter c for countdown and s for stopwatch. ")
typeOfTimer.upper()
print typeOfTimer
if typeOfTimer == "C":
countdown()
elif typeOfTimer == "S":
stopwatch()
else:
print "Invalid type"
有人知道怎么修吗?你知道吗
.upper()
从旧字符串创建新字符串。它不会改变调用方法的字符串。请尝试以下操作:.upper()
不修改变量。相反,用raw_input()
来指定它:以下是您的更新代码:
如您所见,除非赋值,否则仅仅调用
.upper()
不会更改变量。你知道吗相关问题 更多 >
编程相关推荐