+ 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("Слышь чертила, выбери операцию, которую я знаю!")
21 Respostas
+ 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.
+ 1
Here is an example to run here:
https://code.sololearn.com/cOqXfb5wC3jC/?ref=app
On sololearn you cannot have multiple inputs
+ 1
The print command must come after the "else" end
0
Gabriel Ilie
if not num in "+-*/":
...
will do the same without allocating an unnecessary list ;)
0
Your advice don't work
0
but I want to run cod in my sequence
0
I can't understand what's actually wrong with my code
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.
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
0
I have a similar question in my book, if we can post images here?
0
September Tomlinson
Which book???
0
Может кто-нибудь помочь с задачей?
"3. Программа получает на вход последовательность из N целых неотрицательных чисел. Найти количество всех цифр в последовательности чисел.
Ввод данных:
N = 5
23 475 12 1 683"
Нужно решить на Питоне и с использованием цикла while. Понятие того, что можно сделать, есть, но в голову не приходит, как это написать. Буду благодарить вас за помощь столько, сколько хотите, но помощь сильно нужна. Спасибо заранее!
0
Check the indentation
0
Замени *print(float(c))* на *print("Вот твой ответ: " + c)*
0
It's good to have the else part following the elif,,,,,so I think the format is
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!
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))
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("введите второе значение: "))))
0
Kodni tekshirib o‘tirib, kulgili vaziyatlarni eslab ketdim, go‘yoki kichkina xatolik hamma narsani buzib yuboradi. Shunday paytda men stressni kamaytirish uchun https://uz-melbet.com/uz/ orqali o‘yin o‘ynab turaman, chunki u yerda tez yutish imkoniyati bor va vaqt ham maroqli o‘tadi. O‘zbekistonlik sifatida aytishim mumkinki, platforma bizga qulay to‘lov tizimlari, o‘zbek tilidagi interfeys va yaxshi xizmat ko‘rsatadi. Yutganimda shu yerning o‘ziga xos mehmondo‘stligini ham eslatadi, chunki bizning yurtda omad va mehnat birga qadrlanadi. Shu bois Melbet men uchun ishonchli tanlov bo‘lib qoldi.
- 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))