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")
19 Antworten
+ 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")
+ 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
+ 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")
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....
0
def withdraw(amount):
print(str(amount) + " withdrawn!")
try:
a = int(input())
withdraw(a)
except (ValueError, TypeError):
print("Please enter a number")
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")