It might be rediculous but I couldn't get my head around the use of global variables in Python. It throws me syntax errors for the use of the keyword
global
even though, I looked it up exactly that way in the documentation.
I know the code is clumsy for its repetative use of global variables. Anyway, how to use them correctly?
import random
r_list = []
my_list =[3,4,45,7,23,33]
match_list=[]
iteration = 0
number_matches = 0
def fill_random_list():
for i in range(7):
# print (random.randint(1,49))
r_list.append(random.randint(1,49))
def return_matches(lista, listb):
# print set(lista).intersection(listb)
return set(lista).intersection(listb)
def return_number_matches(l_matches):
if l_matches:
return len(l_matches)
def draw_lottery():
while global number_matches < 5:'''
File "C:/Lottery.py", line 27
while global number_matches < 5:
^
SyntaxError: invalid syntax'''
global r_list = []
global match_list = []
fill_random_list()
match_list=return_matches(r_list, my_list)
global number_matches=(return_number_matches(global match_list))
global iteration+=1
if number_matches > 4:
print (str(global iteration) + ';' + str(global number_matches))
def iterate(number):
for i in enumerate(range(number),1):
print('Round: ' + str(i[0]))
draw_lottery()
def main():
iterate(10)
if __name__ == "__main__":
main()