Can someone help me to explain the answer for this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone help me to explain the answer for this code?

count = 0 for letter in 'Snow!': print('Letter # ' + str(count) + ' is ' + str(letter)) count += 1 break print(count)

11th Nov 2018, 6:45 AM
Max Lee
Max Lee - avatar
2 Answers
+ 10
Max Lee If you haven't given proper space in for loop, then this can result in error. Otherwise it will print Letter # 0 is S. Because in for loop, str (count) will result in 0 where 0 is a string and str (letter) will result in S as when for loop will start iterating over Snow, first value will be S. Then because of break loop will break and things outside loop will be printed.
11th Nov 2018, 6:54 AM
Arushi Singhania
Arushi Singhania - avatar
+ 1
Arushi Singhania Thanks for enlightening me
11th Nov 2018, 8:15 AM
Max Lee
Max Lee - avatar