Hey guys im having difficulty writing this program for my homework. can someone please help me. the specification is as follows:
The user selects three distinct numbers (each number must be different) between 0 and 9 inclusive. The computer randomly generates its own 3 distinct numbers (each number must be different) between 0 and 9 inclusive. The user’s numbers and the computer’s numbers are then matched, giving a result of no matches, 1 match, 2 matches or 3 matches. Each game costs the Student £1. The winnings are as follows.
Number of Matches Winnings
0 -
1 -
2 £10
3 £150
any help would be much appreciated!
Python Lottery Game
Page 1 of 19 Replies - 13054 Views - Last Post: 04 December 2016 - 07:08 AM
Replies To: Python Lottery Game
#2
Re: Python Lottery Game
Posted 23 April 2012 - 05:48 PM
What have you tried, where are you stuck?
#3
Re: Python Lottery Game
Posted 24 April 2012 - 03:17 PM
OK so far i have this which allows three numbers to be input by the user now i dont know how to get the program to randomly generate its own 3 different numbers between 0 and 9 and match them. please someone help. thanks
from random import randrange
Random_Number = randrange (0,10)
print " You are required to enter three distinct numbers between 0 and 9 inclusive"
number_1= input ("Enter Number 1: ")
while number_1 <0 or number_1 >9:
print "Invalid Input"
number_1 = input("Enter An Integer less than 10: ")
number_2= input ("Enter Number 2: ")
while number_2 <0 or number_2 >9:
print "Invalid Input"
number_2 = input("Enter An Integer less than 10: ")
number_3 = input ("Enter Number 3: ")
while number_3 <0 or number_3 > 9:
print "Invalid Input"
number_3 = input("Enter An Integer less than 10: ")
This post has been edited by Simown: 25 April 2012 - 06:21 AM
Reason for edit:: Please use code tags
#5
Re: Python Lottery Game
Posted 26 April 2012 - 10:12 PM
to get 1 number between 0 and 9 inclusive, you'd use
using this, you should easily be able to get something from here.
Is this what you're looking for?
import random random.randint(0,9)
using this, you should easily be able to get something from here.
randomNumber_1 = random.randint(0,9) randomNumber_2 = random.randint(0,9) randomNumber_3 = random.randint(0,9)
Is this what you're looking for?
This post has been edited by atraub: 26 April 2012 - 10:14 PM
#6
Re: Python Lottery Game
Posted 27 April 2012 - 04:53 AM
See how this code repeats?
Step 1, write a function:
But you have another check you must make, right? You need to check to make sure you haven't used a number yet. I don't really want to write it for you, so here are some hints.
First, your number_1, number_2... should really be in a list.
Second, you can check if a number is already in a list like so:
Last hint, you should probably pass a list of already selected nunmbers to getNumberFromUser.
Good luck.
number_1= input ("Enter Number 1: ")
while number_1 <0 or number_1 >9:
print "Invalid Input"
number_1 = input("Enter An Integer less than 10: ")
number_2= input ("Enter Number 2: ")
while number_2 <0 or number_2 >9:
print "Invalid Input"
number_2 = input("Enter An Integer less than 10: ")
Step 1, write a function:
def getNumberFromUser(n):
n = input ("Enter Number " + n + ": ")
while n <0 or n>9:
print "Invalid Input"
n = input("Enter An Integer less than 10: ")
return n
number_1 = getNumberFromUser(1)
number_2 = getNumberFromUser(2)
But you have another check you must make, right? You need to check to make sure you haven't used a number yet. I don't really want to write it for you, so here are some hints.
First, your number_1, number_2... should really be in a list.
Second, you can check if a number is already in a list like so:
>>> a = [2,3,5] >>> a [2, 3, 5] >>> 7 in a False >>> 5 in a True >>>
Last hint, you should probably pass a list of already selected nunmbers to getNumberFromUser.
Good luck.
#7
Re: Python Lottery Game
Posted 27 April 2012 - 07:09 AM
thanks guys will try to get it working A
#8
Re: Python Lottery Game
Posted 27 April 2012 - 07:16 AM
CAN SOMEONE PLEASE DELETE MY FIRST PROGRAM SO NO ONE COPYS FROM ME. I TRIED DELETING MY SELF BUT CANT FIND THE EDIT POST OPTION...
#9
Re: Python Lottery Game
Posted 27 April 2012 - 07:23 AM
NO.
You don't seem to get the point of learning through discourse. Or, for that matter, caps lock.
Trust me, no one is going to take your code and make a career out of it. Relax.
You don't seem to get the point of learning through discourse. Or, for that matter, caps lock.
Trust me, no one is going to take your code and make a career out of it. Relax.
#10
Re: Python Lottery Game
Posted 04 December 2016 - 07:08 AM
baavgai, on 27 April 2012 - 07:23 AM, said:
NO.
You don't seem to get the point of learning through discourse. Or, for that matter, caps lock.
Trust me, no one is going to take your code and make a career out of it. Relax.
You don't seem to get the point of learning through discourse. Or, for that matter, caps lock.
Trust me, no one is going to take your code and make a career out of it. Relax.
Ajusta wanted to say that i registered here to cheer up this answer. Thumbs up and let's keep sharing the wealth
Page 1 of 1

New Topic/Question
Reply


MultiQuote




|