You are right, the program is confusing and contains a lot of errors in the logic. For example: "f" as the name of a variable does not make clear what it means. I would have chosen "duplicates" and it should be a boolean. It could contain "True" or "False". It works because "f = 0" also has the meaning of "f = False".
I tried to add some comments. I hope this helps you understand what is going on.
I tried to add some comments. I hope this helps you understand what is going on.
# winningSet is the set of winning numbers. winningSet = (10, 11, 8, 1, 5, 20) # numberInput is a tuple of strings, containing 7 chosen numbers, separated by spaces. numberInput=tuple(input().split()) # It would be better to give some information about the desired input. Like this. # numberInput = tuple(input("Enter 7 different numbers with spaces inbetween: ").split()) # d is a dictionary to check for double entered numbers. # If user chose 3, then d[3] will be set to 1. d = {} # winningPrize is the amount won; 100 pesos for each correct number. winningPrize = 0 # f can be 0 or 1. 0 means: duplicates found; 1 means no duplicates found. f = 1 # There must be 7 items entered. (I think he means 6, the first number is never used.) # If filled correctly, there will be numberInput[0] through numberInput[6], so 7 items. if (len(numberInput) == 7): # range(1,7) means 1 through 6, so numberInput[0] will be ignored. for i in range(1, 7): # The first time d will be empty, so go to the "else". if int(numberInput[i]) in d: # User entered the same number again! So toggle f and exit the for loop. f = 0 break else: # Mark this number as being used. d[int(numberInput[i])] = 1 # If the number is in the winning set, increase the amount. if (int(numberInput[i]) in winningSet): winningPrize += 100 # If f shows there are no duplicates ... if f: # ... and a prize is won ... if winningPrize != 0: # ... show the amount that is won. # But "numberInput[0] makes no sense, it is the number that is ignored. print(numberInput[0], "won", winningPrize, "pesos!") # Else no nothing was won. else: print(numberInput[0], "won nothing!") # Else there are duplicates. else: # This message is not correct. print("No Duplicates") # Else there are not 7 items in numberInput. else: # So this message is not correct. print("Should be 6 numbers")