F
F
FuFX2018-11-03 21:21:22
Python
FuFX, 2018-11-03 21:21:22

Error with else statement, how to solve?

Here is the calculator code:

print('') 
print('') 
print('КАЛЬКУЛЯТОР') 
print('Правила исполнения') 
print('***___***')  
print('Введите СЛОЖИТЬ чтобы сложить 2 числа') 
print('Введите ВЫЧИТАТЬ чтобы вычесть 2 введённых числа')
print('Введите УМНОЖИТЬ чтобы умножить 2 введённых числа')
print('Введите РАЗДЕЛИТЬ чтобы разделить 2 введённых числа')
print('Введите СТЕПЕНЬ чтобы возвести число в степень') 
print('Введите ОСТАТОК чтобы найти остаток от деления') 
print('') 
user_action = input('Введите действие: ') 
print('') 
print('Теперь введите 2 числа с которыми будете производить действия')
chislo = float(input('Введите перввое число: ')) 
chislo1 = float(input('Введите второе число: ')) 

if user_action == 'СЛОЖИТЬ' or user_action == 'сложить' or user_action == 'Сложить':
  result = str(chislo + chislo1) 
  print('Вот результат: ' + result) 
if user_action == 'ВЫЧИТАТЬ' or user_action == 'вычитать' or user_action == 'Вычитать':
  result1 = str(chislo - chislo1) 
  print('Вот результат: ' + result1) 
if user_action == 'УМНОЖИТЬ' or user_action == 'умножить' or user_action == 'Умножить':
  result2 = str(chislo * chislo1) 
  print('Вот результат: ' + result2) 
if user_action == 'РАЗДЕЛИТЬ' or user_action == 'разделить' or user_action == 'Разделить':
  result3 = str(chislo / chislo1) 
  print('Вот результат: ' + result3) 
if user_action == 'СТЕПЕНЬ' or user_action == 'степень' or user_action == 'Степень':
   result4 = str(chislo ** chislo1) 
   print('Вот результат: ' + result4) 
if user_action == 'ОСТАТОК' or user_action == 'остаток' or user_action == 'Остаток':
  result5 = str(chislo // chislo1) 
  print('Вот результат: ' + result5) 
else:
    print('Неправильный ввод')
print('')
print('******')
print('Программа закончена')

When I enter for example add and enter 2 numbers, it gives me the answer and then displays 'invalid input' which should only be if I enter something incorrectly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Helow19274, 2018-11-03
@FuFX

The first time if, and then elif. Otherwise, else only affects the block where the remainder is.
Type:

if action == 1:
    do_something()
elif action == 2:
    do_another_thing()
else:
    print('Неправильный ввод')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question