Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning Python
#1
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() 
Reply


Messages In This Thread
Learning Python - by LordHill - Oct-18-2016, 03:19 PM
RE: Learning Python - by nilamo - Oct-18-2016, 03:33 PM
RE: Learning Python - by LordHill - Oct-18-2016, 04:05 PM
RE: Learning Python - by metulburr - Oct-18-2016, 05:16 PM
RE: Learning Python - by nilamo - Oct-18-2016, 05:52 PM
RE: Learning Python - by LordHill - Oct-18-2016, 07:41 PM
RE: Learning Python - by Skaperen - Oct-19-2016, 12:32 AM
RE: Learning Python - by LordHill - Oct-20-2016, 11:34 PM
RE: Learning Python - by buran - Oct-20-2016, 08:20 AM
RE: Learning Python - by LordHill - Oct-27-2016, 12:04 AM
RE: Learning Python - by Skaperen - Oct-27-2016, 03:40 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020