- 2

I put exactly the same code as was in example for simple calculator.......still having problem.....I have given my code here.......help plz....

print(options) print("enter 'add' to add two numbers") print("enter 'subtract' to subtract two munbers") print("enter'divide' to divide two numbers") print("enter'multiply' to multiply two numbers") print("enter'quit' to end the programm") user_input=input(":") if user_input=="quit": break elif user_input=="add": num 1=float(input("enter a number:")) num 2=float(input("enter another number:")) result=str(num 1 +bnum 2) print("The answer is" + result) elif user_input=="subtract": num 1=float(input("enter a number:")) num 2=float(input("enter another number:")) result=str(num 2 - num 1) print("The answer is" + result) elif user_input=="divide": num 1=float(input("enter a number:")) num 2=float(input("enter another number:")) result=str(num 1/num 2) print("The answer is" + result ) elif user_input=='multiply': num 1=float(input("enter a number:")) num 2=float(input("enter another number:")) result=str(num 1*num 2) print("The answer is" +result) else print ("unknown output")

8th Aug 2016, 8:34 AM
Teenager
Teenager - avatar
10 ответов
0
I love this app, not so much writing the code in qa. :) I see a couple of things: 1. variables have space (num 1 instead of num1 or num_1, same with num 2) 2. your elifs aren't indented not quite sure since you cast the result as string, but maybe your print func needs work example: #cast as string as you have it print("The answer is %s" % result) #omit the cast print("The answer is %d" % result) the print above may be deprecated in Python 3, I'm thinking in 2.7...
8th Aug 2016, 10:28 AM
Izz
Izz - avatar
0
Izz what do you mean by elifs are not intended? ????it also gives the same error but I couldn't get that........
8th Aug 2016, 11:49 AM
Teenager
Teenager - avatar
0
you must indent all code inside of blocks, here conditional statements. so I notice you have your code indented after your first if, to end the if block, you must unindent your elif line, then indent all the code within that elif, and so on for remaining elif statements. like this: if x == "yes": #do something here and next line sum = "correct" elif x == "no": #more code here sum = "incorrect" else: #other code here sum = "unknown. I do binary. can't compute" #the rest of the code no matter sum value does that make sense? dumb logic above, just showing how indentation is important to python. sorry, driving to work..will check back shortly.
8th Aug 2016, 12:03 PM
Izz
Izz - avatar
0
Can you exactly tell me what kind of code should I enter.....and please just tell me exactly mistake and also correct that in your answer.........
8th Aug 2016, 4:08 PM
Teenager
Teenager - avatar
0
I will, but I want to be sure you understand and others that who may see this post. indentation is crucial in Python. I'll get to a web interface soon, maybe it's just the way I see the code on the android app. Can you please tell me where the example code is for the above? I'd like to compare and explain why there is a problem, not just fix it without everyone understanding the issue. Can you also give me the errors you're receiving? if we can't work this out here, I'll give you my email and / or Skype so to rule out paste formatting and to carry this conversation so not too have to wait for the other to post back. :) I'm about twenty mins from being able to check all of this.
8th Aug 2016, 4:16 PM
Izz
Izz - avatar
0
Home>Control structures >Simple Calculator.....there you can this code......
8th Aug 2016, 4:31 PM
Teenager
Teenager - avatar
0
I'm having trouble getting this qa pulled up in web interface. let me try to pm you.
8th Aug 2016, 5:53 PM
Izz
Izz - avatar
0
look at the comments at the bottom within the Simple Calculator course. I saw decent ideas. if you want me to continue to help, I'm happy to. email me at <my username>@<my favorite OS (see my avatar)>.com anyone here is welcome to contact me via email
9th Aug 2016, 1:57 AM
Izz
Izz - avatar
0
wat?
29th Jan 2019, 7:24 PM
mohammed ajmal
mohammed ajmal - avatar
0
shut up you guys dont know nothing man
9th Oct 2019, 10:12 AM
M.Saleh Khan
M.Saleh Khan - avatar