-1

with the code I'm trying to accomplish is that I'm asking the user to for a number between 1 and 12 and then display the times table for that number. The while loop checks if it's not a number or if its less than 1 or more than 12 then it will loop until it input is correct. However I get the error (written on the title) Any ideas how to fix this?

user_input = print('Input number between 1-12: ')


#While loop to keep checking the following conditions
while (not user_input.isdigit()) or (int(user_input < 1) or int(user_input > 12)):
  print("Please input a number between 1-12")
  user_input = print("Input selection >>  ")

#Now convert user_input into an int
user_input = int(user_input)
print('------------------------------------------')
print()
print(f'This is the {user_input} times table')
print()
for i in range(1,13):
  print(f'{i} x {user_input} = {i*user_input}')
Q.T.π
  • 49
  • 6
  • Does this answer your question? [How to read keyboard-input?](https://stackoverflow.com/questions/5404068/how-to-read-keyboard-input) – Macattack Oct 08 '20 at 15:44

2 Answers2

0
user_input = print('Input number between 1-12:')

The above line only print out Input number between 1-12: to the console, it does not ask for the user to input anything. Since the print() function displays the string inside it and returns None, you get the error that you're getting.

If you want to take user input, then use the input() function like,

user_input = input("Input number between 1-12: ")

The above line will prompt the user to input something while also displaying the text

Riptide
  • 472
  • 3
  • 14
  • I didn't catch the print instead of the input issue. Very stupid of me. Thanks for answering my problem! – Q.T.π Oct 08 '20 at 16:01
0
user_input = input('Input number between 1-12: ')


#While loop to keep checking the following conditions
while (not user_input.isdigit()) or (int(user_input)< 1 or int(user_input) > 12):

list of issues:

  • you printed instead of input to receive input from the user
  • you attempted to use < on instances of str and int, instead you should check this outside the int conversion to make sure that you trying to use < which both operands are int
Yossi Levi
  • 1,258
  • 1
  • 4
  • 7
  • My fault, was looking at the code several times I didn't catch the print instead of input issue. My bad. Thanks for your answer! – Q.T.π Oct 08 '20 at 16:00