2016-09-28 44 views
-4

我最近开始学习Python。我从来没有编码,但它似乎是一个挑战。我做的第一件事就是这个计算器。但是,我似乎无法让它工作。Simpel Python Calculator - 语法错误 - 缩进错误

while True: 
    print("Typ 'plus' to add two numbers") 
    print("Typ 'min' to subtract two numbers") 
    print("Typ 'multiplication' multiply two numbers") 
    print("Typ 'division' to divide two numbers") 
    print("Typ 'end' to abort the program") 
    user_input = input(": ") 

    if user_input == "end" 
     break 

    elif user_input == "plus":   
     num1 = float(input("Give a number: "))     
     num2 = float(input("Give another number: ")) 
     result = str(num1 + num2)         
     print("The anwser is: " + str(result)) 

    elif user_input == "min": 
     num1 = float(input("Give a number: "))     
     num2 = float(input("Give another number: "))    
     result = str(num1 - num2)         
     print("The anwser is: " + str(result)) 

    elif user_input == "maal": 
     num1 = float(input("Give a number:"))     
     num2 = float(input("Give another number: "))    
     result = str(num1 * num2)         
     print("The anwser is: " + str(result)) 

    elif user_input == "deel": 
     num1 = float(input("Give a number: "))     
     num2 = float(input("Give another number: "))    
     result = str(num1 + num2)         
     print("The anwser is: " + str(result)) 

    else: 
     print ("I don't understand!") 

我知道它可能会有些愚蠢,我仍然非常学习。只是试图提升新技能,而不是打扰我的朋友,他们知道如何编写代码。

+1

我们不能帮你,如果你不告诉我们是什么问题。 –

+1

请阅读[问]和[mcve],然后[编辑]您的帖子。 – davidism

+0

它说这是无效的语法:if user_input ==“end” break –

回答

0

你错过了一个冒号的这个后if语句

if user_input == "end" 
    break 

应该是:

if user_input == "end": 
    break