python中输入17=x会引起错误_python中的输入错误

你好,用户8311329,

问题

当您使用字符串作为输入时,请使用raw_input()函数。而且您正在使用的所有程序都使用;,所以python提供了一个带有out ;(colon)来执行程序的功能。在

解决方案

试试这个代码while True:

print("please choose one of these available options: \n1. Add \n2. Subtract \n3. Multiply \n4. Divide \n5. Quit \nType in exactly as shown or the calculator won't work")

choice = str(raw_input("From above choice any one option: "))

if(choice == "quit"):

break

elif(choice == "divide"):

num1 = float(input("Please enter a number:"))

num2 = float(input("Please enter another number:"))

output = num1/num2

print "The answer is:",output

elif(choice == "multiply"):

num1 = float(input("Please enter a number:"))

num2 = float(input("Please enter another number:"))

output = num1*num2

print "The answer is:",output

elif(choice == "subtract"):

num1 = float(input("Please enter a number:"))

num2 = float(input("Please enter another number:"))

output = num1-num2

print "The answer is:",output

elif(choice == "add"):

num1 = float(input("Please enter a number:"))

num2 = float(input("Please enter another number:"))

output = num1+num2

print "The answer is:",output

else:

print("Invalid Input. Try again")

例如,如果有其他用户运行此程序,请使用您的应用程序,以便此人不了解输入的确切内容,因此代码编写高效且完美,以便其他用户容易理解并给出建议,不要使用此代码插入字符串,而是使用数字输入进行选择,就像我给出的示例(我不只是给出简单的示例而且您还添加了更多的输入验证)

^{pr2}$

我希望我的回答有帮助。

如有任何疑问请评论。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值