9 Replies - 13054 Views - Last Post: 04 December 2016 - 07:08 AM Rate Topic: -----

#1 gamergonch   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

Python Lottery Game

Posted 23 April 2012 - 03:28 PM

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!


Is This A Good Question/Topic? 0
  • +

Replies To: Python Lottery Game

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2770
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: Python Lottery Game

Posted 23 April 2012 - 05:48 PM

What have you tried, where are you stuck?
Was This Post Helpful? 0
  • +
  • -

#3 gamergonch   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

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

Was This Post Helpful? 0
  • +
  • -

#4 gamergonch   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

Re: Python Lottery Game

Posted 26 April 2012 - 04:03 PM

SOMEBODY? ANYBODY?
Was This Post Helpful? 0
  • +
  • -

#5 atraub   User is offline

  • Pythoneer
  • member icon

Reputation: 837
  • View blog
  • Posts: 2,271
  • Joined: 23-December 08

Re: Python Lottery Game

Posted 26 April 2012 - 10:12 PM

to get 1 number between 0 and 9 inclusive, you'd use
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

Was This Post Helpful? 0
  • +
  • -

#6 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: Python Lottery Game

Posted 27 April 2012 - 04:53 AM

See how this code repeats?
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.
Was This Post Helpful? 0
  • +
  • -

#7 gamergonch   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

Re: Python Lottery Game

Posted 27 April 2012 - 07:09 AM

thanks guys will try to get it working A
Was This Post Helpful? 0
  • +
  • -

#8 gamergonch   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-April 12

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...
Was This Post Helpful? 0
  • +
  • -

#9 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

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.
Was This Post Helpful? 1
  • +
  • -

#10 Anakin_   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-December 16

Re: Python Lottery Game

Posted 04 December 2016 - 07:08 AM

View Postbaavgai, 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.


Ajusta wanted to say that i registered here to cheer up this answer. Thumbs up and let's keep sharing the wealth
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1