What is wrong with my code??? Что не так с моим кодом??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is wrong with my code??? Что не так с моим кодом???

Please, help me! When I try to run my code idle tells me next: multiple statements found while compiling a single statement. My code: Помогите пожалуйста! Когда я пытаюсь запустить свой код, то айдл выдаёт мне следующую ошибку multiple statements found while compiling a single statement Мой код: # My first script а = float(input("Введите первое число: ")) num = input("Че делать будем?(+,-,*,/): ") b = float(input("Введите второе число: ")) if num == "+": c = a + b elif num == "-": с = a - b elif num == "*": с = a * b elif num == "/": c = a / b print(float(c)) else: print("Слышь чертила, выбери операцию, которую я знаю!")

26th Mar 2020, 2:35 PM
Дудич Артем
Дудич Артем - avatar
20 Answers
+ 1
print(float(c)) must be at the same indentation as c=a/b and must be put in if statement and in all elif statements.
26th Mar 2020, 2:54 PM
Gabriel Ilie
Gabriel Ilie - avatar
+ 1
Here is an example to run here: https://code.sololearn.com/cOqXfb5wC3jC/?ref=app On sololearn you cannot have multiple inputs
26th Mar 2020, 4:03 PM
Gabriel Ilie
Gabriel Ilie - avatar
+ 1
The print command must come after the "else" end
28th Mar 2020, 7:19 AM
Ali Khosroanjam
Ali Khosroanjam - avatar
0
Gabriel Ilie if not num in "+-*/": ... will do the same without allocating an unnecessary list ;)
26th Mar 2020, 3:19 PM
visph
visph - avatar
0
Your advice don't work
26th Mar 2020, 3:55 PM
Дудич Артем
Дудич Артем - avatar
0
but I want to run cod in my sequence
26th Mar 2020, 4:06 PM
Дудич Артем
Дудич Артем - avatar
0
I can't understand what's actually wrong with my code
26th Mar 2020, 4:07 PM
Дудич Артем
Дудич Артем - avatar
0
I’m sorry but in my last comment I was wrong. You can input multiple values. You have to put them on separate lines. Please check my code again to see the differences from yours.
26th Mar 2020, 4:21 PM
Gabriel Ilie
Gabriel Ilie - avatar
0
It also was a problem with the a variable due to encoding I belive. I just delete it and write it again for the input
26th Mar 2020, 4:22 PM
Gabriel Ilie
Gabriel Ilie - avatar
0
I have a similar question in my book, if we can post images here?
27th Mar 2020, 5:21 AM
September Tomlinson
September Tomlinson - avatar
0
September Tomlinson Which book???
27th Mar 2020, 10:44 AM
Raj Laxmi Verma
Raj Laxmi Verma - avatar
0
Может кто-нибудь помочь с задачей? "3. Программа получает на вход последовательность из N целых неотрицательных чисел. Найти количество всех цифр в последовательности чисел. Ввод данных: N = 5 23 475 12 1 683" Нужно решить на Питоне и с использованием цикла while. Понятие того, что можно сделать, есть, но в голову не приходит, как это написать. Буду благодарить вас за помощь столько, сколько хотите, но помощь сильно нужна. Спасибо заранее!
27th Mar 2020, 11:05 AM
Олень
Олень - avatar
0
Check the indentation
27th Mar 2020, 8:32 PM
Siddharth Ramnani
Siddharth Ramnani - avatar
0
Замени *print(float(c))* на *print("Вот твой ответ: " + c)*
27th Mar 2020, 11:59 PM
Neron
0
It's good to have the else part following the elif,,,,,so I think the format is
28th Mar 2020, 3:59 AM
Phillip Santei
Phillip Santei - avatar
0
It's called computer science with python.... I think, I don't remember honestly, but the author is Sunita Arora I guess.... I'm sorry if I am wrong!
28th Mar 2020, 4:39 AM
September Tomlinson
September Tomlinson - avatar
0
a = float (a на кириллице) elif * (c на кириллице) elif - (c на кириллице) print(float(c)) прерывает череду условий if / else и должно быть написано ниже ////////////////////////////// Мой код: # My first script a = float(input("Введите первое число: ")) num = input("Че делать будем?(+,-,*,/): ") b = float(input("Введите второе число: ")) if num == "+": c = a + b elif num == "-": c = a - b elif num == "*": c = a * b elif num == "/": c = a / b else: print("Слышь чертила, выбери операцию, которую я знаю!") print(float(c))
28th Mar 2020, 2:34 PM
Lafaed
Lafaed - avatar
0
#или можно сделать так: def calculator(x,z,y): if z=="+": return x+y elif z=="-": return x-y elif z=="*": return x*y elif z=="/": return x/y else: print("не верная команда!") return print("Результат:",calculator(int(input("введите первое значение: ")),input("введите операцию: "),int(input("введите второе значение: "))))
28th Mar 2020, 2:48 PM
Lafaed
Lafaed - avatar
- 1
Another way of doing it is : if not num in ["+", "-", "*", "/"]: print("Слышь чертила, выбери операцию, которую я знаю!") else: if num == "+": c = a + b elif num == "-": с = a - b elif num == "*": с = a * b elif num == "/": c = a / b print(float(c))
26th Mar 2020, 2:59 PM
Gabriel Ilie
Gabriel Ilie - avatar
- 1
🤔😂😂😂
28th Mar 2020, 1:09 PM
__ pek3p5__
__ pek3p5__ - avatar