I'm a newbie... and studying about global
keyword.
This code creates a random string.
I think line 8, string.append(word[x])
make error on this code
because string
is a global variable, so must be required global
keyword. (global string)
But this code runs correctly... Why can run correctly...?
import random
word = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.split(" ")
string = []
n = int(input())
def get(leng) :
for i in range (0, leng) :
x = random.randint(0, len(word)-1)
string.append(word[x])
sen = ''.join(string)
return sen
print(get(n))