Ask coding questions

← Back to all posts
Im fairly new to code and my input is messed up can someone help?
MidgetMan (0)

My input says it is not a number and i need to run it through a discount system it was working but i tried to implement a lottery system and it broke

Answered by 19ecal (228) [earned 5 cycles]
View Answer
19ecal (228)

This is happening because your except is catching the error in your code. What you want to do is change line 22 to newPrice=discountPrice(totalPrice)

19ecal (228)

It is bad practice to catch all exceptions with just a plain except, try and figure out what the error you want to catch is (in this case ValueError from converting an invalid string to a float) and just catch that one like this

    num=float(input("number: "))
except ValueError:
    print("only numbers plz")
MidgetMan (0)

Thanks a lot:)@19ecal

19ecal (228)

@MidgetMan No problem :) Could you mark my answer as the correct one?