Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Calculator Help
#2
You are converting to float on lines 8 and 10, but you aren't trying to catch errors until lines 12-20. If you want to catch the errors being raised, you need to either move your try blocks back to where the float(input(...)) calls are, or you need to wait to convert to float until the try block.

You are going to have problems later on, though. You are just printing a warning if an error is raised, you are not actually dealing with the problem. In your example, you may print a warning that the second number is invalid, but then your program is still going to subtract Hi from 54. You probably want to put everything into a while loop:

while True:
    try:
        num1 = float(input('Enter second number: '))
        break
    except ValueError:
        print('Please enter a valid number.')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Simple Calculator Help - by destr0yer667 - May-22-2019, 01:52 PM
RE: Simple Calculator Help - by ichabod801 - May-22-2019, 02:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple tip calculator DragonG 5 5,487 Oct-23-2018, 04:54 AM
Last Post: snippsat
  Python Program to Make a Simple Calculator jack_sparrow007 2 10,304 Oct-19-2018, 08:32 AM
Last Post: volcano63
  Need help with simple calculator. ghost0fkarma 3 2,820 Sep-11-2018, 07:40 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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