0

В чем ошибка

coffee = ["Café Latte", "Caffe Americano", "Espresso", "Cappuccino", "Macchiato"] choice = int(input()) if choice => 1 and =< 5: print(coffee[choice]) else: print(choice + "error")

6th Jan 2022, 2:05 PM
Johny Luma
Johny Luma - avatar
14 ответов
+ 3
Try to do print(choice, " error") or print("{0} error".format(choice)) or print(str(choice)+" error") all of this should work but you only need one
6th Jan 2022, 2:40 PM
Bartek
+ 1
You need to start from 0 and end at 4 becouse indexes start from 0 if 0<=choice and choice <=4
6th Jan 2022, 2:16 PM
Bartek
+ 1
If you want to start form 1 you need to need to change print(coffe[choice]) after if to print(coffe[choice-1]) or change choice var to choice = int(input())-1
6th Jan 2022, 2:19 PM
Bartek
+ 1
Use same datatypes
8th Jan 2022, 9:56 AM
Yakesh Balaji Raja.P.
Yakesh Balaji Raja.P. - avatar
0
If choice >= 1 and choice <= 5: You forgot about choice after and and you placed => and =< instead of >= and <=
6th Jan 2022, 2:09 PM
Bartek
0
А как мне заставить код начинать отчет не с нуля а с 1?
6th Jan 2022, 2:10 PM
Johny Luma
Johny Luma - avatar
0
Нет все равно и с if 1<= choice <= 5: не работает
6th Jan 2022, 2:13 PM
Johny Luma
Johny Luma - avatar
0
How i can input start 1 but indexes start 0. I mean simebody write 1, programm print " Caffe Latte" on 0
6th Jan 2022, 2:18 PM
Johny Luma
Johny Luma - avatar
0
Ou yes you right. Its workin. 1<= choise <= 5 just need delete? Its dont needed for code?
6th Jan 2022, 2:21 PM
Johny Luma
Johny Luma - avatar
0
It's needed becouse if needs some condition (eg. soms values to compare)
6th Jan 2022, 2:25 PM
Bartek
0
Ok but why dont workin end code coffee = ["Café Latte", "Caffe Americano", "Espresso", "Cappuccino", "Macchiato"] choice = int(input()) if 1<= choice <= 5: print(coffee[choice-1]) else: print(choice + "error") Print(choice + "error") dont working. I should delet choice and finally they write error. But I want his write for exemple "7 error"
6th Jan 2022, 2:38 PM
Johny Luma
Johny Luma - avatar
0
Yes thank its work)))) now i know little more)) thanks
6th Jan 2022, 2:44 PM
Johny Luma
Johny Luma - avatar
0
Короче, старый добрый повтор: if choice=>1 and choice=<5:
7th Jan 2022, 9:09 PM
Nikita Zavertkin
Nikita Zavertkin - avatar
0
А разве так писать нельзя?
7th Jan 2022, 10:10 PM
Johny Luma
Johny Luma - avatar