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.

30th Aug 2022, 1:23 PM
Szymon Moczarski
Szymon Moczarski - avatar
5 Réponses
+ 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
30th Aug 2022, 1:52 PM
Lisa
Lisa - avatar
+ 3
Akash Negi The thread is about exceptions in Python. Do you want to contribute anything beyond "Haha"?
30th Aug 2022, 5:52 PM
Lisa
Lisa - avatar
+ 2
Is there a task description?
30th Aug 2022, 1:40 PM
JaScript
JaScript - avatar
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 😀.
3rd Sep 2022, 2:05 PM
Szymon Moczarski
Szymon Moczarski - avatar
- 3
Haha
30th Aug 2022, 5:30 PM
Akash Negi
Akash Negi - avatar