https://www.pythonmorsels.com/p/2dcsb/
i have this simple currency exchange code but everytime it gets to float(val) it raises a value error ive debugged this for an hour straight with no answer
#π Currency Exchange value error
34 messages Β· Page 1 of 1 (latest)
@timid wing
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
could you send a copy of the error that you're getting?
im not getting an error because i have an except block
i can't tell if the error is in my code or vs itself
Comment it out and send what you get
Have u try and re did the code
bet
well
uh
the same thing
i guess the problem isnt in float(val)
do you have a traceback now?
its at all_symblos = f.read()
wait its a UnicodeDecodeError?
oh yeah why is the encoding cp1252
alr i put the encoding as utf-8
and it works π
ig that was the issue
thank you
yeah, UnicodeDecodeError is a subtype of ValueError, so catching ValueError suppresses it
generally you want your try/except blocks to cover the minimum amount of code that they need to in order to avoid this kind of thing
what can i use instead of value error?
in get_amount_currency
if the user inputs a string instead of a numebr
catching ValueError is correct if you want to report that the user inputted an invalid float, but the try/except should only cover the line where you expect an error to be raised
in your case that would be line 57
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.