Why does this code keep running? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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

28th Dec 2019, 3:44 PM
Pattern
Pattern - avatar
4 Réponses
+ 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
28th Dec 2019, 3:56 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
S is a int but s2 is string by default. You should write, S2=int (input (""))
28th Dec 2019, 4:11 PM
Abhishek Patel
+ 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
28th Dec 2019, 3:56 PM
Ipang
+ 1
Thank guys ♡
28th Dec 2019, 4:15 PM
Pattern
Pattern - avatar