我是Python的新手,我的程序遇到了一些麻烦。每当我输入大于第一个数字的第二个数字时,“mCounter”应设置为false,并且由于有一个while循环,它应该让我再次输入数字位数。出于某种原因,这不会发生。每当我输入第二个数字大于第一个时,程序就会停止。 任何帮助将不胜感激。 谢谢!
import random
#Introduction
print('Choose the mode that you would like to enter by typing the letters in the brackets')
problem = input('Multiplication(M) Addition (A) Subtraction (S) Division (D): ')
#Multiplication
if problem == 'M' or problem == 'm':
mCounter = False
while mCounter == False:
mInput1 = int(input('Enter the amount of digits you would like in the first number you are multiplying.\nThe first number should be greater or equal to the second number: '))
mInput2 = int(input('Enter the amount of digits you would like in the second factor: '))
mCounter = True
if mInput2 > mInput1:
print('The first number MUST be greater or equal to the second number. Please try again!')
mCounter == False
else:
print('nothing')
答案 0 :(得分:2)
要设置mCounter
的值,请执行以下操作:
mCounter = False
而不是:
mCounter == False
您所拥有的代码只是比较 mCounter
与False
的值,然后忽略该比较的结果。
答案 1 :(得分:0)
而不是:
mCounter == False
你想要:
mCounter = False
您需要一项任务,而不是条件检查。
答案 2 :(得分:0)
声明mCounter == False
不会改变mCounter
。您必须使用=
进行分配。
if mInput2 > mInput1:
print('The first number MUST be greater or equal to the second number. Please try again!')
mCounter = False #<-- use = instead of ==