Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Loop This Code
#3
It doesn't make any sense to catch the error and break out of the program. This will continue until you press ctrl+c. If you type something other than a number the program prints the error message but continues running.
while True:
    try:
        print(float(input('num1 >> ')) + float(input('num2 >> ')))
    except ValueError as msg:
        print(msg)
Reply


Messages In This Thread
How to Loop This Code - by Michael1 - Dec-09-2021, 06:42 PM
RE: How to Loop This Code - by menator01 - Dec-09-2021, 07:34 PM
RE: How to Loop This Code - by deanhystad - Dec-09-2021, 08:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to convert while loop to for loop in my code? tatahuft 4 802 Dec-21-2024, 07:59 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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