444,050 Members | 1,009 Online
Need help? Post your question and get tips & solutions from a community of 444,050 IT Pros & Developers. It's quick & easy.

# Else error

 P: 5 Python Version 2.0 Windows Vista (I know, I know...) Im very new to python and have only been doing it for two weeks. print 'Type in lowercase!'; String_Var = raw_input ('Add, Divide, Multiply or Subtract? '); if 'add' in String_Var: AddVar1 = raw_input ('Number 1: '); AddVar2 = raw_input ('Number 2: '); Add_Var = AddVar1 + AddVar2; print AddVar1, '+', AddVar2, '=', Add_Var; else: if 'subtract' in String_Var: SubVar1 = raw_input ('Number 1: '); SubVar2 = raw_input ('Number 2: '); Sub_Var = SubVar1 - SubVar2; print SubVar1, '+', SubVar2, '=', Sub_Var; else: if 'multiply' in String_Var: MultiplyVar1 = raw_input ('Number 1: '); MultiplyVar2 = raw_input ('Number 2: '); Multpiply_Var = MultiplyVar1 + MultiplyVar2; print MultiplyVar1, '+', MultiplyVar2, '=', Multiply_Var; else: if 'divide' in String_Var: DivVar1 = raw_input ('Number 1: '); DivVar2 = raw_input ('Number 2: '); Div_Var = DivVar1 + DivVar2; print DivVar1, '+', DivVar2, '=', Div_Var; else: print 'Syntax Error.' I created this code, but it keeps coming up with 'else' syntax error! Mar 13 '08 #1
8 Replies

 P: 5 Thank you, the else problem is solved now. What is the command for 'divide'? Mar 13 '08 #3

 100+ P: 314 Expand|Select|Wrap|Line Numbers while True:     String_Var = raw_input ('Add, Divide, Multiply, Subtract, or Quit? ').lower()       if 'add' in String_Var:         AddVar1 = float(raw_input ('Number 1: '))         AddVar2 = float(raw_input ('Number 2: '))         Add_Var = AddVar1 + AddVar2         print AddVar1, '+', AddVar2, '=', Add_Var     elif 'sub' in String_Var:         SubVar1 = float(raw_input ('Number 1: '))         SubVar2 = float(raw_input ('Number 2: '))         Sub_Var = SubVar1 - SubVar2         print SubVar1, '-', SubVar2, '=', Sub_Var     elif 'mul' in String_Var:         MultiplyVar1 = float(raw_input ('Number 1: '))         MultiplyVar2 = float(raw_input ('Number 2: '))         Multiply_Var = MultiplyVar1 * MultiplyVar2         print MultiplyVar1, '*', MultiplyVar2, '=', Multiply_Var     elif 'div' in String_Var:         DivVar1 = float(raw_input ('Number 1: '))         DivVar2 = float(raw_input ('Number 2: '))         Div_Var = DivVar1 / DivVar2         print DivVar1, '/', DivVar2, '=', Div_Var     elif 'q' in String_Var:         break     else:         print 'Syntax Error.' This one's fixed for actual use of numbers... which I didn't notice before. When you use raw_input it takes the user's input as a string. You need to type cast into either float() or int() in order to perform mathematical operations. Mar 13 '08 #4