Oct-18-2016, 03:19 PM
I decided to learn Python. Yesterday I was reading about for and while loops. The tutorial ended with an assignment of making a lottery picker. So, I did. Probably much fast and cleaner ways to do it, but here is what I came up with, using both a for loop and a while loop. The wife and kids don't care, had to show someone, so here it is.
import random import sys numbers=[] def skip (): print("\n") def pick(): skip() skip() skip() skip() skip() while len(numbers) < 5: pick=random.choice(range(1,69)) if pick in numbers: pick=random.choice (range (1,69)) else: numbers.append(pick) pball=random.choice(range(1,26)) num=sorted(numbers) skip() print ("\t ", end=' ') count=0 for i in range(len(num)): print("", end=' ') print(num[0+count], end=' ') count+=1 skip() print("\t Power Ball = ", end=' ') print(pball) skip() skip() skip() pickem() def pickem(): again=input("\tENTER To Pick Or Q To Quit - \n\n") again=again.lower() if again.startswith("q"): sys.exit else: numbers[:]=[] pick() pickem()