0
Cash Out in intermediate python
def withdraw(amount): print(str(amount) + " withdrawn!") def chceck(nums): try: x = int(nums) return True except: print('Please enter a number') return False #your code goes here try: cash = input() while chceck(cash) == False: cash = input() else: withdraw(cash) except: pass That's the code I used. It seems it doesn't work on page without try: and except: when I try to run the code on sololearn app. Works perfectly wen tested in python . My question is. Did I went too far with it? and even if so, is there an option to make what I made better.
5 Answers
+ 4
Are you referring to task 29.2 in Python Intermediate?
It would be helpful if you put your code in a script on sololearn playground.
From inspecting your code, I think you are making it more complicated than it needs to be. Consider the following approach:
try:
# get input
# convert input to integer, if it fails (ValueError), except-part will be executed; if not the next line of try will be executed
# call withdraw() with converted input
except ValueError:
# print the phrase as specified in the task description
+ 3
Akash Negi The thread is about exceptions in Python. Do you want to contribute anything beyond "Haha"?
+ 2
Is there a task description?
0
Lisa Yeah that's the one i was refering too. I just went too many curves on straight road and made it way more complicated that it should be. I guess beginigns are always a bit bendy đ.
- 3
Haha