while True 循环中的 Python 错误

用户6146480
total = 0                                                   
print ("Enter first number")
num1 = input()
print ("Enter 1)Add 2)Minus 3)Multiply 4)Divide")
choice = input()

while True:
    print("Wrong Answer Pick Again")
    print("Enter 1)Add 2)Minus 3)Multiply 4)Divide")
    choice = input()
    if choice => 1 and choice =< 4:
        break

if choice == 1:
  print ('Enter second number')
  num2 = input()
  total = num1 + num2 

elif choice == 2:
  print ('Enter second number')
  num2 = input()
  total = num1 - num2
elif choice == 3:
  print ('Enter second number')
  num2 = input()
  total = num1 * num2
elif choice == 4:
  print ('Enter second number')
  num2 = input()
  total = num1 / num2

print("Total")
print (total)

我在“if choice => 1 and choice =<4:”上遇到语法错误,有人可以帮忙吗。我尝试了很多不同的东西,但没有任何效果。

魔王28

这个脚本应该适合你:

total = 0                                                   

print ("Enter 1)Add 2)Minus 3)Multiply 4)Divide")
choice = int(input())

for _ in range(int(input("total test cases"))):


    if choice >= 1 and choice <= 4:
        if choice == 1:
            print ("Enter first number")
            num1 = int(input())
            print ('Enter second number')
            num2 = int(input())
            total = num1 + num2
            print("Total is: ",total)
            choice=int(input("enter choice again"))

        elif choice == 2:
            print ("Enter first number")
            num1 = int(input())
            print ('Enter second number')
            num2 = int(input())
            total = num1 - num2
            print("Total is: ",total)
            choice=int(input("enter choice again"))

        elif choice == 3:
            print ("Enter first number")
            num1 = int(input())
            print ('Enter second number')
            num2 = int(input())
            total = num1 * num2
            print("Total is: ",total)
            choice=int(input("enter choice again"))

        elif choice == 4:
            print ("Enter first number")
            num1 = int(input())
            print ('Enter second number')
            num2 = int(input())
            total = num1 / num2
            print("Total is: ",total)
            choice=int(input("enter choice again"))
    else:
        print("wrong number entered")
        choice=int(input("enter again"))

注意:如果您觉得此答案有帮助,您可以将此答案标记为正确

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

while循环中的Python错误

来自分类Dev

while循环中的Python错误

来自分类Dev

while 循环中的错误

来自分类Dev

如何在Python的while循环中修复此错误?

来自分类Dev

为什么在“While True”循环中使用 continue 时会出现回溯错误

来自分类Dev

或条件在while循环中python

来自分类Dev

Python:while循环中的函数

来自分类Dev

While循环中的Python随机

来自分类Dev

while 循环中的 Python 线程

来自分类Dev

随着时间的流逝,Python“ while True”循环中出现睡眠混乱

来自分类Dev

错误处理后的while循环中出现Python Traceback错误

来自分类Dev

Python 列出 for 循环中的错误

来自分类Dev

在while循环中来自stringbuilder的StringIndexOutOfBoundsException错误

来自分类Dev

while循环中的Perl语法错误

来自分类Dev

PHP在while循环中输出记录-错误

来自分类Dev

在while循环中错误地求和

来自分类Dev

While循环中的C ++分段错误

来自分类Dev

在while循环中测试整数错误

来自分类Dev

分段错误,fgets在while循环中

来自分类Dev

NoneType错误与while循环中的列表?

来自分类Dev

子手游戏-While循环中的错误

来自分类Dev

while 循环中的 PHP 和 MySQL 错误

来自分类Dev

while as 循环中的语法错误

来自分类Dev

在Python的while循环中追加列表会出现错误消息“列表索引超出范围”

来自分类Dev

当在while循环中使用break语句时,Python程序给出错误的输出

来自分类Dev

Python中的while循环错误

来自分类Dev

Python while 循环(不是从 while 循环中出来的)

来自分类Dev

Python:在while循环中遍历csv

来自分类Dev

Python:在“ while”循环中嵌套“ If”语句吗?