It seems that you are mixing different Python here (Python 2.x vs Python 3.x) ... This is mostly correct:
nb = input('Choose a number: ')
The problem is that it is only supported in Python 3. As @sharpner said, for older versions of Python (2.x) you need to use the raw_input function:
nb = raw_input('Choose a number: ')
If you want to convert it to a number, try:
number = int(nb)
... although you need to consider that this may throw an exception:
try: number = int(nb) except ValueError: print("Invalid number")
And if you want to print the number using formatting, it is recommended to use Python 3 str.format() :
print("Number: {0}\n".format(number))
Instead:
print('Number %s \n' % (nb))
But both parameters ( str.format() and % ) work in both Python 2.7 and Python 3.
Baltasarq Mar 23 2018-11-12T00: 00Z
source share