Python Forum
How to send an error message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send an error message
#1
I'm not quite sure how to structure this question so I'm going to use an example
Let's say I have a program that asks a user for a number which I am going to use later
, I would do something like this

number = int(input("Please give me a number: "))
answer = number + 4
print("Your number plus 4 is " + str(answer) )
However, if the user inputs the letter form of the number such as "two" or "three"
they would receive an error message. I want to be able to create an error message with a While True loop so that if they did type in the number in letter form, or if they input something incorrectly for a similar program wouldn't crash. Is there a way to do this?
Reply
#2
Remember that int will raise a ValueError if the value passed to it can't be converted to an integer. So, catch the exception and handle it (if you don't know about exception handling with try and except, now would be a good time to learn).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 932 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Send Error when attaching files JamesAinsworth 1 554 Aug-07-2023, 11:10 PM
Last Post: deanhystad
  Another Error message. the_jl_zone 2 943 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  email Library: properly send message as quoted-printable malonn 3 1,266 Nov-14-2022, 09:31 PM
Last Post: malonn
  how to check if someone send a message in a discord channel? Zerolysimin 1 742 Nov-06-2022, 11:10 AM
Last Post: Larz60+
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,677 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  understanding error message krlosbatist 1 1,856 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
  Error message pybits 1 35,964 May-29-2021, 10:26 AM
Last Post: snippsat
  Bluetooth send message after connecting? korenron 2 2,623 Apr-26-2021, 05:50 AM
Last Post: korenron
  f-string error message not understood Skaperen 4 3,267 Mar-16-2021, 07:59 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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