Python Forum
New to the language. What am I doing incorrectly here?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to the language. What am I doing incorrectly here?
#2
Please use the python tags to show your code. It's much easier to understand.

Python here is declaring that the thing that was input was not an integer. We can't see your session to know what was wrong. If you want to test if it's really an integer rather than exiting if it's not, you can wrap the action in a try/except clause.

Also, you label the raw input as number, and after converting to an int(), you label it user_input. That seems backward to me. Maybe more like this:

import sys
user_input = input("Provide a number: ")
try:
    number = int(user_input)
except ValueError:
    print(f"{user_input} doesn't look like an integer to me.  Exiting")
    sys.exit()
if number % 10 == 0:
    print("Your number is a multiple of 10.")
else:
    print("Your number is not a multiple of 10.")
Reply


Messages In This Thread
RE: New to the language. What am I doing incorrectly here? - by bowlofred - Jun-19-2020, 11:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing to file ends incorrectly project_science 4 2,746 Jan-06-2021, 06:39 PM
Last Post: bowlofred
  my openpyxl use is too slow, am I reading rows incorrectly? Clunk_Head 2 8,386 Apr-30-2020, 10:29 PM
Last Post: deac33
  list is printing incorrectly.. anna 1 2,123 May-18-2019, 12:12 PM
Last Post: ichabod801
  Code is Outputting Incorrectly mikerosz94 0 2,113 Sep-01-2017, 01:28 PM
Last Post: mikerosz94

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020