+ 4

What is the largest number this code prints? for i in range(10): if i > 5: print(i) break else: print("7")

I think the question is wrong because the program prints 7 within range 0 to 5.So 7 is the largest number?But the answer is 6.Why?

6th Jul 2019, 6:28 PM
Aung Myo Tun
Aung Myo Tun - avatar
8 Antworten
+ 9
True, ChillPill but the question asks what number is printed, not what integer. It should be 7 either way IMO
6th Jul 2019, 7:05 PM
Helena
Helena - avatar
+ 7
Helena I think what ChillPill was saying is that because the 6 being printed out from the loop is an integer, it could be classified as a number while the 7 would not (in the context of the problem) considering it's a string. Either way though, I feel the question was phrased a little weirdly and can definitely throw some people off
6th Jul 2019, 7:09 PM
Faisal
Faisal - avatar
+ 5
Answer is 6
1st Mar 2021, 8:05 AM
Sasanka Vikum Vitharana
Sasanka Vikum Vitharana - avatar
+ 1
Thank for your answers.
6th Jul 2019, 7:18 PM
Aung Myo Tun
Aung Myo Tun - avatar
+ 1
the IF statement: "if i>5" only becomes true when i = 6 then it moves on to the " print(i)" so it prints out a 6 then break ends the sequece
24th Jun 2022, 5:41 PM
Brian Fontenot
0
6
17th Feb 2022, 1:56 PM
Boniface Samanda