-4

I'm new with Python and I'm having a bit of trouble with my program. Whenever I input a second number that is larger than the first number "mCounter" should be set to false, and since there is a while loop, it should ask me to input the number of digits again. For some reason this doesn't happen. Whenever I input a second number that is larger than the first the program just stops. Any help would be greatly appreciated. Thanks!

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')
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
albad
  • 27
  • 1
  • 2

3 Answers3

2

To set the value of mCounter, do this:

mCounter = False

rather than this:

mCounter == False

The code you have there is just comparing the value of mCounter with False, and then ignoring the result of that comparison.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
0

Instead of:

mCounter == False

you want:

mCounter = False

You need an assignment, rather than a conditional check.

Matt
  • 437
  • 3
  • 10
0

The statement mCounter == False doesn't change mCounter. You have to use = for assignment.

if mInput2 > mInput1:
    print('The first number MUST be greater or equal to the second number. Please try again!')
    mCounter = False #<-- use = instead of ==
jh314
  • 27,144
  • 16
  • 62
  • 82