Калькулятор \ Calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Калькулятор \ Calculator

Where is incorrect?(Code below) Где здесь не правильно?(Код ниже) Появляется такая "SyntaxError: inconsistent use of tabs and spaces in indentation" и такая ошибка "TabError: inconsistent use of tabs and spaces in indentation". Первая в Питоне на винде, вторая в приложении. Так не понял где он пробелы увидел их там нет, отступы правил, правил, правил... результат не изменен или выдает другую ошибку. while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(":") if user_input == "quit": break elif user_input == "add": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 + num2) print("The result is" + result) elif user_input == "subtract": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result=str(num1 - num2) print("The result is" + result) elif user_input == "multiply": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 * num2) print("The result is" + result) elif user_input == "divide": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 / num2) print("The result is" + result) else: print("Wrong!")

19th Nov 2016, 5:49 PM
Ulan Ortangalyiev
Ulan Ortangalyiev - avatar
4 Answers
0
check the lines with 'elif' - they are not properly indented. Ошибки сообщают о том, что у тебя проблемы с отступами в коде. у тебя отступы неправильно введены (на строках с elif) - if и elif должны находиться на одном уровне.
19th Nov 2016, 6:50 PM
Rill Chritty
Rill Chritty - avatar
0
Твой код, после исправления ошибок, работает. Вот исправленная версия ниже: while True: print("Options") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(":") if user_input == "quit": break; elif user_input == "add": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 + num2) print("The result is " + result) elif user_input == "subtract": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 - num2) print("The result is " + result) elif user_input == "multiply": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 * num2) print("The result is " + result) elif user_input == "divide": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 / num2) print("The result is " + result) else: print("Wrong")
19th Nov 2016, 7:20 PM
Rill Chritty
Rill Chritty - avatar
0
Спасибо, работает) На винде работает, в приложении тоже работает, но выдает такую ошибку "Traceback (most recent call last): File "..\Playground\", line 9, in <module> user_input = input(":") EOFError: EOF when reading a line "
19th Nov 2016, 8:13 PM
Ulan Ortangalyiev
Ulan Ortangalyiev - avatar
0
Да, я тоже это заметил на Sololearn. Если в программе необходимо ввести строки или числовые значения больше раза, программа нормально здесь работать не будет (так бывает и на С++ и Java). Лучше такие программы тестировать на компьютере.
19th Nov 2016, 10:55 PM
Rill Chritty
Rill Chritty - avatar