0
Guys..the substract function is not working..saying no output..wats the mattr
26 odpowiedzi
+ 9
You should place your inputs for num_1 and num_2 before the first condition checker (if ...)
Because when your elif substract case is reached, no number has been defined.
+ 9
To make it easier with your input, you can use '+' and '-' instead of writing 'add' and 'substract', and you can ask for only one line of input and then use split():
n1,op,n2 = input().split() # getting input
n1,n2 = map(float,[n1,n2]) # turning n1 and n2 to floats
if op == '+' :
print (n1 + n2)
elif op =='-' :
print (n1 - n2)
input needs to be separated by white spaces then, as in:
"27 - 13"
or
"33 + 8"
+ 9
Choe
😂😂😂 right!
I just tried to keep some learning material here.
+ 8
You don't need to difine them twice, it's better to define your numbers once, but before starting your conditions.
+ 8
i checked it with 2 digits, works fine.
+ 8
Are you sure you entered your input on multiline ?
this way:
substract
35
12
+ 8
And, as i said, you should declare num_1 and 2 once only ...
+ 8
Hey, don't give up !
Your code is working, you just need to be very precise with the way you write your input.
+ 7
Another detail:
you don't need to turn your results to strings before printing.
print (num_1 - num_2)
will work
+ 7
Ok, now your input should be like this:
"42
13
substract"
the order of your input counts.
+ 7
did you write it on 3 lines, exactly like this ? because it should work, it works for me.
Also: you don't need str(input())
because input() is already a string
+ 5
You're checking if the user_input equals " substract" (note the space). You need to remove the space
+ 3
What Cépagrave said... Didn't notice it 🤓
+ 2
Cépagrave but do that and its the same as stripping down to eval() input.
0
Is it okay now #Anna ?
0
So Cépagrave i should be defining num1 and num2 twice??
0
But guys..its working now
.but i cant do calculations with 2 digits
0
Idk...now i cant substract showing no output..
0
Yeahhh..