0
while_continue-list-break
instead of just going through sessions, I was actually planning to make a simple code using those four but I dunno whee I went wrong but I got an error. can anyone help me sort it out??plz https://code.sololearn.com/cHEMvzmmNkfW/#py
9 Answers
+ 3
Mode_Of_transport = ['Car','Bus','Train']
Here you used small t but in loop usin capital T in
Mode_Of_Transport[].
So it's error.
In loop, you shloud use break instead of continue to stop while loop..
And next while is also Infinite loop if condition is true...
Actually there is no need to use while loop, not changing any values in loop, you need only one iteration. So instead of while write if..
And also rest code works fine, but you are comparing string not integers..
Input function takes input as string..
If i<=50: #here 50 is number
if i<='50' : #here '50' is string
+ 1
I have actually corrected my code. But when I enter 100. It shows me an error. Can anyone explain why ??
+ 1
I said you in my first post to convert the input to integer, it's important. I don't know why you downvoted it!
look at this: when you enter '100' python do an alphabetical comparison and then '100'<'60' and it ends in the else statement which will make an infinite loop!
+ 1
in the else statement, replace continue with break and also add a break statement to the last while loop
but I still don't know why you're using while loop there!
0
convert the input to Integer or float,
distance =int( input(" Approximately Enter The amount Of Distance You Should Travel in KM "))
then do the test with numbers, rather than strings:
if distance <= 60:
....
but in any case, you'll have an infinite loop. why are you using the while loop?
0
Mani where is the corrected code?
0
Thanks. I got it
0
Wait. I will change it



