Guys..the substract function is not working..saying no output..wats the mattr | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Guys..the substract function is not working..saying no output..wats the mattr

https://code.sololearn.com/chaosap0gkeo/?ref=app

9th May 2019, 9:40 AM
Y AD Ù
Y AD Ù - avatar
26 Answers
+ 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.
9th May 2019, 10:06 AM
Cépagrave
Cépagrave - avatar
+ 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"
9th May 2019, 12:17 PM
Cépagrave
Cépagrave - avatar
+ 9
Choe 😂😂😂 right! I just tried to keep some learning material here.
9th May 2019, 6:59 PM
Cépagrave
Cépagrave - avatar
+ 8
You don't need to difine them twice, it's better to define your numbers once, but before starting your conditions.
9th May 2019, 10:21 AM
Cépagrave
Cépagrave - avatar
+ 8
i checked it with 2 digits, works fine.
9th May 2019, 10:22 AM
Cépagrave
Cépagrave - avatar
+ 8
Are you sure you entered your input on multiline ? this way: substract 35 12
9th May 2019, 10:27 AM
Cépagrave
Cépagrave - avatar
+ 8
And, as i said, you should declare num_1 and 2 once only ...
9th May 2019, 10:36 AM
Cépagrave
Cépagrave - avatar
+ 8
Hey, don't give up ! Your code is working, you just need to be very precise with the way you write your input.
9th May 2019, 12:04 PM
Cépagrave
Cépagrave - avatar
+ 7
Another detail: you don't need to turn your results to strings before printing. print (num_1 - num_2) will work
9th May 2019, 10:35 AM
Cépagrave
Cépagrave - avatar
+ 7
Ok, now your input should be like this: "42 13 substract" the order of your input counts.
9th May 2019, 10:45 AM
Cépagrave
Cépagrave - avatar
+ 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
9th May 2019, 10:49 AM
Cépagrave
Cépagrave - avatar
+ 5
You're checking if the user_input equals " substract" (note the space). You need to remove the space
9th May 2019, 10:02 AM
Anna
Anna - avatar
+ 4
Y Åđ Û Cépagrave Works fine for me. (add & sub)
9th May 2019, 11:07 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
What Cépagrave said... Didn't notice it 🤓
9th May 2019, 10:07 AM
Anna
Anna - avatar
+ 2
Cépagrave but do that and its the same as stripping down to eval() input.
9th May 2019, 6:52 PM
Choe
Choe - avatar
0
Is it okay now #Anna ?
9th May 2019, 10:05 AM
Y AD Ù
Y AD Ù - avatar
0
So Cépagrave i should be defining num1 and num2 twice??
9th May 2019, 10:08 AM
Y AD Ù
Y AD Ù - avatar
0
But guys..its working now .but i cant do calculations with 2 digits
9th May 2019, 10:13 AM
Y AD Ù
Y AD Ù - avatar
0
Idk...now i cant substract showing no output..
9th May 2019, 10:25 AM
Y AD Ù
Y AD Ù - avatar
0
Yeahhh..
9th May 2019, 10:27 AM
Y AD Ù
Y AD Ù - avatar