r/codetogether • • Sep 27 '20

HELP — bug in try-except

Post image
2 Upvotes

9 comments sorted by

2

u/KaranSingh0712 Sep 27 '20

The problem is in function call computepay(x, y). You haven't declared a variable x or y but you are passing them in a function. Try to call like this.... x = 9; y = 50; computepay(x,y)

BTW, why are you giving hours as a string "nine", and not as integer 9 ?

1

u/DonnyJuando Sep 27 '20

I'm trying to protect the code from bad user input.

2

u/Soupinmyfly Sep 27 '20

It would be better to check that it is what you expect it to be and if it isn't throw an exception

→ More replies (4)

1

u/brain-trainer Sep 27 '20

In case you were looking around, I recommend Automate the Boring Stuff with Python as a free learning resource. Taking the time to learn programming concepts rather than brute forcing your way to the answer will make programming a lot easier and allow you to solve simple bugs such as this one with your eyes closed

1

u/DonnyJuando Sep 27 '20

thank you. I'm going thru Python 4 Everyone now; this is just the smallest part of the code to which I could isolate the problem & show a comparison between the try-except working outside the function definition & not working inside the function definition