Python Forum
I keep getting errors and I'm lost!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I keep getting errors and I'm lost!
#3
Your while loop should not be in the function. It should be where you ask for input. So you keep looping, asking for input each time. Once you get the input, you need to check it for three things. If it is 'Quit', you need to exit the loop. If it is a valid float, you should send it to computer_grade. Otherwise, you reply with 'Bad input.'.

You sort of have that with the try/except block. Here's a way you might use it: First, get the input. Then, in the try block, send it to computer_grade. If that raises an error (because of an invalid float) it goes to the except block. In the except block have an if/else statement. If the input is quit, exit the loop; otherwise print 'bad input'.

The reason you are getting the error is that you are not checking that you have a valid float before you send it to computer_score. When you enter correct values, you are only getting to enter two because your loop is in the wrong place. You ask once at the top, then you ask once in the computer_grade function, then you return on line 61, breaking out of the loop. The computer_grade function should do nothing but translate the numeric grade into a letter grade. Take all of the looping and inputting out of there.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: I keep getting errors and I'm lost! - by ichabod801 - Oct-27-2018, 03:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am completely lost on this homework assignment a36 1 1,818 Feb-21-2022, 06:01 AM
Last Post: buran
  Very Lost vollynez 3 1,926 Oct-02-2020, 09:09 PM
Last Post: Yoriz
  I got lost in the program Gadev 1 1,921 Nov-11-2018, 05:50 PM
Last Post: j.crater
  test..and I'm already lost sannixinc 1 2,560 Feb-22-2018, 09:09 PM
Last Post: glidecode
  Completly lost about to fail my class! crakacheezy 7 4,688 Dec-28-2017, 11:50 PM
Last Post: mepyyeti

Forum Jump:

User Panel Messages

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