Есть ответ 👍

Python Здравствуйте, сегодня впервые работаю с этим языком программирования. Не понимаю, в чём ошибка. До while (всё, что на первой фотке) всё работало, а начиная со второго фото программа не открывается Буду благодарна за ответ)

114
236
Посмотреть ответы 2

Ответы на вопрос:

WERDF342
4,7(81 оценок)

Объяснение:

Итак, было 2 места с опечатками.

Во-первых, строка 29 - ввод числа - действия. Стоял плюс перед input(). option = +input(...

Во-вторых, строка 34 - вывод результата сложения, результат суммы не присоединялся к строке (забыт оператор +).

Исправил и приложил код ниже.

P.S. Вообще тема калькуляторов - вещь интересная. Она стоит на границе двух областей: компиляторов (парсинг, синтаксический анализ, etc.) и символьных вычислений (Это про то, как по текстовому выражению решить дифференциальное уравнение или построить график функции, или решить квадратное уравнение аналитически).

Если тебя так интересует эта тема, можешь продолжить написанием более функционального калькулятора для обратной польской записи, например.

Успехов в обучении!

Код:

like = "Great, I'm too! So let's enjoy math together)"

hate = "But I do like! So I can help you as well)"

what = "Could you please answer Yes or No)"

anyway = "Although I can't understand you again, let's do this!"

option = "6"

i = "7"

name = input("Hey, what's your name? ")

print("Wow, what a beautiful name ")

math = input(name + ", do you like mathematics? ")

if math.lower() == "yes":

   print(like)

elif math.lower() == "no":

   print(hate)

else:

   print(what)

   print("         ")

   math = input(name + ", do you like mathematics? ")

   if math.lower() == "yes":

       print(like)

   elif math.lower() == "no":

       print(hate)

   else:

       print(anyway)

print("         ")

while i == "7":

   print("I can find the sum(1), difference(2), product(3), fraction(4), of two numbers and raise number to the power(5) or end this game(0)")

   option = input("select the needed option by sending corresponding number   ")  # HERE! You have placed a plus before an input()

   if option == "1":

       n1 = float(input("So you have chosen the sum. Enter the first number   "))

       n2 = float(input(f"And what number you wanna add to {n1} ?   "))

       sum = n1+n2

       print(f"The sum of {n1} and {n2} is {sum}")  # And THERE! You have written down ... + "is" sum) without a concatination plus

       print("      ")

   elif option == "2":

       n1 = float(input("So you have chosen the difference. Enter the first number   "))

       n2 = float(input("And the second?   "))

       dif = n1 - n2

       print(f"{n1} - {n2} = {dif}")

       print("      ")

   elif option == "3":

       n1 = float(input("So you have chosen the production. Enter the first number   "))

       n2 = float(input("And the second one   "))

       prod = n1 * n2

       print(f"The result is {prod}")

       print("      ")

   elif option == "4":

       n1 = float(input("So you have chosen the fraction. Enter the first number   "))

       n2 = float(input(f"And {n1} is divided by...   "))

       fr = n1 / n2

       print(f"So, the result is {fr}")

       print("      ")

   elif option == "5":

       n1 = float(input("What number should I raise to the poser?   "))

       n2 = float(input(f"And what is exponent (the little number above {n1}) ?   "))

       power = n1 ** n2

       print(f"{n1}^{n2} is {power}")

       print("      ")

   elif option == "0":

       input("The game is ended!")

       break

   else:

       print("I don't have any options like this. Try again.")

MaxZvanie
4,5(17 оценок)

3

Объяснение:

это текст с ссылкой

Популярно: Информатика