HI,
Just starting out with python. Throught my book, a real basic book from visual steps I came to make below code. I think I understand all the working but one thing potentially puzzles me.
I use this: for x in range(0,4): a few times. Now I understand what the loop does and that is is nested further down the code but, how does the interpreter understand that x comes from the number range which was initially put in under the variable "code". Even thinking about the indentation does not explain it to me fully.
Anybody who can explain in baby logic :-) how python interpreter knows that x is processing the numbers given in the variable code (assuming I have that right).
Any help appreciated.
Thanks,
Ivo
Just starting out with python. Throught my book, a real basic book from visual steps I came to make below code. I think I understand all the working but one thing potentially puzzles me.
I use this: for x in range(0,4): a few times. Now I understand what the loop does and that is is nested further down the code but, how does the interpreter understand that x comes from the number range which was initially put in under the variable "code". Even thinking about the indentation does not explain it to me fully.
Anybody who can explain in baby logic :-) how python interpreter knows that x is processing the numbers given in the variable code (assuming I have that right).
Any help appreciated.
Thanks,
Ivo
import random import sys while True: # invoer code door de speler code = input("geef je code van 4 cijfers op (stop met 9999):") # controleer op cijfers only if code.isdigit(): #stop met het spel if int(code) == 9999: sys.exit() # controleren op 4 cijfers if len(code) == 4: # controleer dat de cijfers < 1 of > 6 fout=0 for x in range(0,4): if int(code[x]) < 1 or int(code[x]) > 6: fout=1 if fout == 0: # controleer of all getallen verschillen zijn gelijk=0 for x in range(0,4): for y in range(0,4): if x != y and code[x] == code[y]: gelijk=1 if gelijk == 0: break else: print ("twee of meer cijfers zijn hetzelfde") else: print("cijfers mogen niet lager dan 1 of hoger dan 6 zijn") else: print("er zijn te weinig of te veel cijfers") else: print("er staan letters in") print("all is well")