- Oct 31, 2012
- 8
- 0
- 0
Hi, I'm working on this question:
Write a program to generate at random a ticket for Lotto 6-49. This should be six numbers between 1 and 49 (remember, no duplicate numbers!). Store the numbers in a list. The program should also include an option to generate a ticket in which the user can specify some of the six numbers and the program generates the rest. The program should also include an option to generate a ticket in which the user can forbid some of the six numbers.
I'm almost done and my problem is i'm having trouble in limiting the lotto_add and lotto_forbidden functions so that they only run a maximum of 6 times so that my lottery number list will at most contain 6 numbers as the question suggests. Thank you for your time
	
	
	
		
			
			Write a program to generate at random a ticket for Lotto 6-49. This should be six numbers between 1 and 49 (remember, no duplicate numbers!). Store the numbers in a list. The program should also include an option to generate a ticket in which the user can specify some of the six numbers and the program generates the rest. The program should also include an option to generate a ticket in which the user can forbid some of the six numbers.
I'm almost done and my problem is i'm having trouble in limiting the lotto_add and lotto_forbidden functions so that they only run a maximum of 6 times so that my lottery number list will at most contain 6 numbers as the question suggests. Thank you for your time
		Code:
	
	 import random
def lotto_add():
    picks=[]
    user_add=str(input('Would you like to specify some of the six numbers? Enter "Y" for yes and "N" for no: ' ).strip())
    while user_add=='Y' or user_add=='y': 
        user_num=int(input('Enter a number: ').strip())
        while user_num in picks:
            print('You cannot pick the same number twice. Please enter a different number: ')
            user_num=int(input('Enter a number').strip())
        user_add=str(input('Would you like to enter another number? Enter "Y" for yes and "N" for no: '))
        picks.append(user_num)
    return picks
def lotto_forbidden():
    forbidden=[]
    user_forbid=str(input('Would you like to forbid some of the six numbers? Enter "Y" for yes and "N" for no: ' ).strip())
    while user_forbid=='Y' or user_forbid=='y': 
        user_num=int(input('Enter a number: ').strip())
        while user_num in forbidden:
            print('You cannot pick the same number twice. Please enter a different number: ')
            user_num=int(input('Enter a number').strip())
        user_forbid=str(input('Would you like to enter another number? Enter "Y" for yes and "N" for no: '))
        forbidden.append(user_num)
    return forbidden
def lotto(picks,forbidden):
    a=6-len(picks)
    for i in range (0,a):
        num=random.randint(1,49)
        while num in picks and num in forbidden:
            num=random.randint(1,49)
        picks.append(num)
    return picks 
				
		 
			 
 
		 
 
		 
 
		 
 
		 
 
		
 Facebook
Facebook Twitter
Twitter