+ 2

Check error[solved]

total = 0 ticket = 100 passenger = 1 while passenger >= 5: age = int(input()) if age <= 3: 'continue' else: total = total + ticket print(total)

11th Mar 2022, 4:56 AM
Arunesh Kishore
13 Answers
+ 1
total = 0 ticket = 100 passenger = 1 while passenger <=5: age = int(input()) if (age <= 3): passenger = passenger + 1 'continue' else: passenger = passenger + 1 total = total + ticket print (total)
11th Mar 2022, 5:19 AM
Arunesh Kishore
+ 2
Hi. I think that the problem it's that passenger value is always 1, so the while loop will never start because the condition is passenger >= 5.
11th Mar 2022, 5:09 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 2
This is familiar to me. I think this is somewhere in python courses or in the community exercises section. What Mohamed WB write is the correct answer but don't continue until you understand that because if not it's going to be more and more complicated to you
11th Mar 2022, 5:16 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 2
Ohh. Mohamed WB You forgot about include passenger += 1 in each iteration so the code don't go forever
11th Mar 2022, 5:19 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 2
Arunesh Kishore Yes but you are using passenger = passenger + 1 while passenger += 1 is a little bit shorter. And you are using it two times, once in the if statement and once in the else statement, you can do it just after or before the age = int(input()) line so you just have to use it one time
11th Mar 2022, 5:23 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 1
Can you correct this code
11th Mar 2022, 5:11 AM
Arunesh Kishore
+ 1
I need to know the exercise first
11th Mar 2022, 5:13 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 1
total = 0 ticket = 100 passenger = 1 while passenger <= 5: age = int(input()) passenger += 1 if age <= 3: 'continue' else: total = total + ticket print(total)
11th Mar 2022, 5:20 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 1
total = 0 ticket = 100 passenger = 1 while passenger <=5: age = int(input()) if (age <= 3): passenger = passenger + 1 'continue' else: passenger = passenger + 1 total = total + ticket print (total) This code is also working in that case
11th Mar 2022, 5:21 AM
Arunesh Kishore
+ 1
In this case it's not that important but in larger projects where you have a lot of lines of code you want to make it as effective as possible
11th Mar 2022, 5:26 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 1
You can also write total += ticket, instead of total = total + ticket The += symbol is to sum something to that variable so you don't have to write the variable name 2 times
11th Mar 2022, 5:29 AM
Marcos Ezequiel Hernández Damaglia
Marcos Ezequiel Hernández Damaglia - avatar
+ 1
Ok
11th Mar 2022, 10:24 AM
Arunesh Kishore
0
للو
12th Mar 2022, 11:41 PM
مجوهرات لولوةالمملكة
مجوهرات لولوةالمملكة - avatar