0

String Input Help

I was needing help with this situation. The question on a problem for a lesson said,” x = input(Enter a Number: ) print(x) “ It says that the “user” entered 4 into the input. The final answer to the question was 4. But when I actually ran a code like that, it said “Enter a Number: 4” Is there a way to tell the user, “enter a number” without it popping up in the output when printed?

20th May 2019, 1:11 AM
Matthew
Matthew - avatar
4 Answers
0
perhaps conditions when user inputs invalid type? x = input() if not x.isdigit(): print("Enter a number")
20th May 2019, 2:46 AM
Choe
Choe - avatar
+ 5
If you don't want the instruction "Enter a number" to show up in the output, you may have to use a graphical user interface like tkinter (which SoloLearn doesn't support) - e.g. https://www.python-course.eu/tkinter_entry_widgets.php. If you just want the instruction and input on separate lines, you can do x = input("Enter a Number:\n" )
20th May 2019, 2:53 AM
David Ashton
David Ashton - avatar
0
the input you’ve given has prompt, which are messages joined with the input. Simply remove it x = input()
20th May 2019, 2:31 AM
Choe
Choe - avatar
0
I still, however wish to tell them to put integers. Not letters or something. would that require coding in html, css, and/or js too?
20th May 2019, 2:38 AM
Matthew
Matthew - avatar