How this program works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How this program works?

import random st = "CBSEONLINE" num = random.randint(0,3) n = 9 while st[num] != "L": print(st[n] + st[num] + "#", end ="") num = num + 1 n = n - 1 https://code.sololearn.com/cnJOVbcDFjd8/?ref=app

20th Jul 2021, 6:09 AM
Sagar Yadav
Sagar Yadav - avatar
1 Answer
+ 5
ミ Shiva 彡 , just a short remark: in this line the variable < n > is set to the value of 9, which is related to the length of the string stored in < st >: n = 9 this is a kind of hard-coding that can lead to an < out of index > error, or to the fact that not all characters will be processed when the used the string is different from ones when creating the code. to avoid this, it would be better to use this expression: n = len(st) - 1
20th Jul 2021, 10:58 AM
Lothar
Lothar - avatar