+ 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)
13 Antworten
+ 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)
+ 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.
+ 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
+ 2
Ohh. Mohamed WB You forgot about include passenger += 1 in each iteration so the code don't go forever
+ 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
+ 1
Can you correct this code
+ 1
I need to know the exercise first
+ 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)
+ 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
+ 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
+ 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
+ 1
Ok
0
للو