Trying to solve cash out in intermediate python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Trying to solve cash out in intermediate python

Only two test case seem to come out write, and i don't where i'm getting it wrong This is the code i used: def withdraw(amount): print(str(amount) + " withdrawn!") try: num=input() x=withdraw(num) except (ValueError, TypeError): print:("Please enter a number")

30th Mar 2021, 11:05 AM
Simisola Osinowo
Simisola Osinowo - avatar
18 Answers
+ 10
this code might work ........ def withdraw(amount): print(str(amount) + " withdrawn!") try: a = int(input()) withdraw(a) except (ValueError, TypeError): print("Please enter a number")
23rd May 2021, 12:39 PM
Abhishek Biswas
Abhishek Biswas - avatar
30th Mar 2021, 12:32 PM
Simisola Osinowo
Simisola Osinowo - avatar
+ 2
My other solution def withdraw(amount): print(f'{amount} withdrawn!') while True: try: withdraw(int(input())) except: print("Please enter a number") break
15th Dec 2021, 1:49 AM
Samnith Vath
Samnith Vath - avatar
+ 1
You have to typecast num to integer . and remove (:) after print in last line.
30th Mar 2021, 11:25 AM
TOLUENE
TOLUENE - avatar
+ 1
Md Sayed 🇧🇩🇧🇩 thanks it worked
30th Mar 2021, 12:32 PM
Simisola Osinowo
Simisola Osinowo - avatar
+ 1
Hey Guyz , Here I have Got the perfect solution do check it ... Happy learning !! def withdraw(amount): print(str(amount) + " withdrawn!") #your code goes here try: num=int(input()) x=withdraw(num) except (ValueError, TypeError): print("Please enter a number")
10th Sep 2023, 10:24 AM
V Balavardhanreddy
0
What is the error is coming out And also tell me what is the function of that code
30th Mar 2021, 11:13 AM
Tirthen Patel
Tirthen Patel - avatar
0
Post the problem description pls.. I think you need to take input as a numbers...
30th Mar 2021, 11:25 AM
Jayakrishna 🇮🇳
0
calls the corresponding withdrawal method. In case the input is not a number, the machine should output "Please enter a number". Use exception handling to take a number as input, call the withdraw() method with the input as its argument, and output "Please enter a number", in case the input is not a number.
30th Mar 2021, 11:32 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
An ATM machine takes the amount to be withdrawn as input and calls the corresponding withdrawal method. In case the input is not a number, the machine should output "Please enter a number". Use exception handling to take a number as input, call the withdraw() method with the input as its argument, and output "Please enter a number", in case the input is not a number.
30th Mar 2021, 11:32 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
try : int(num) except : print('please enter a number') Take input, and call method with input. Next try this code within the method. If input is not a number then it raise error otherwise don't.. So modify this according to needed in description...
30th Mar 2021, 11:41 AM
Jayakrishna 🇮🇳
0
try : int(num) except : print('please enter a number') Take input, and call method with input. Next try this code within the method. If input is not a number then it raise error otherwise don't.. So modify this according to needed in description...
30th Mar 2021, 11:41 AM
Jayakrishna 🇮🇳
0
I tried this and it still did not work def withdraw(amount): print(str(amount) + " withdrawn!") try: num=input() int(num) except : print:("Please enter a number")
30th Mar 2021, 11:57 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
Use it. def withdraw(amount): print(str(amount) + " withdrawn!") try: num=int(input()) withdraw(num) except : print:("Please enter a number")
30th Mar 2021, 11:59 AM
TOLUENE
TOLUENE - avatar
0
Just try this code try : a = int(input()) except TypeError : print("please enter a number")
30th Mar 2021, 12:02 PM
Tirthen Patel
Tirthen Patel - avatar
0
Simisola Osinowo you have : after print in statement print("Please enter a number"). So its causing problem. But i said to try this way... def withdraw(amount): try: int(num) print(str(amount) + " withdrawn!") except : print("Please enter a number") Call this method with input taken....
30th Mar 2021, 12:07 PM
Jayakrishna 🇮🇳
0
def withdraw(amount): print(str(amount) + " withdrawn!") try: a = int(input()) withdraw(a) except (ValueError, TypeError): print("Please enter a number")
10th Nov 2022, 8:35 AM
Pooja Patel
Pooja Patel - avatar
0
The following answer is my code def withdraw(amount): print(str(amount) + " withdrawn!") #code is entered try: withdraw(int(input())) except (ValueError,TypeError): print("Please enter a number") # for simplify try : withdraw(int(input())) except : print("Please enter a number")
2nd Dec 2023, 7:09 AM
vahid kamrani
vahid kamrani - avatar