Trying to solve cash out in intermediate python | Sololearn: Learn to code for FREE!

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")

3/30/2021 11:05:09 AM

Simisola Osinowo

16 Answers

New Answer

+3

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")

+2

Jayakrishna🇮🇳 thanks

+2

My other solution def withdraw(amount): print(f'{amount} withdrawn!') while True: try: withdraw(int(input())) except: print("Please enter a number") break

+1

You have to typecast num to integer . and remove (:) after print in last line.

+1

Md Sayed 🇧🇩🇧🇩 thanks it worked

0

What is the error is coming out And also tell me what is the function of that code

0

Post the problem description pls.. I think you need to take input as a numbers...

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.

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.

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...

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...

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")

0

Use it. def withdraw(amount): print(str(amount) + " withdrawn!") try: num=int(input()) withdraw(num) except : print:("Please enter a number")

0

Just try this code try : a = int(input()) except TypeError : print("please enter a number")

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....