+ 1
Why does this code keep running?
My input is 3 I want it to stop printing when it reaches 3 but it doesn't though my commands while s!=s2 and if s==s2 : break whyyyy? s=0 s2=input() while s!=s2: print(s) s+=1 # i tried if if s==s2: break # it keeps printing i dont know the mistake
4 Antworten
+ 2
Saja Ali , you should convert s2 to int, otherwise it's a string. Please look at the code 🐱
https://code.sololearn.com/cyR9hLZhsZc6/?ref=app
+ 3
S is a int but s2 is string by default.
You should write,
S2=int (input (""))
+ 1
<s> is an integer, while <s2>is a string, always remember that `input` function returns string. You can convert <s2> into integer using `int` function.
s = 0
s2 = int(input())
# `int` converts to integer
while s != s2:
print(s)
s += 1
s2 = int(input())
# read <s2> value again
+ 1
Thank guys ♡