# Problem with how to use the program.

Page 1 of 1

## 1 Replies - 767 Views - Last Post: 14 September 2012 - 09:19 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=292014&amp;s=190a54784b33d8d7b60e86219a83a571&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 beltway

Reputation: 0
• Posts: 2
• Joined: 14-September 12

# Problem with how to use the program.

Posted 14 September 2012 - 07:46 PM

Hey guys, I'm having difficulty writing this program for my homework and I am a little confuse as to how to continue to write the program. Can someone please help me? the specification is as follows:

In the Lotto, two numbers, one from 1 - 30 and a second from 31 - 60 are chosen, with each choice independent from the other and each of the possible numbers is equally likely to be chosen. If you match one number you receive \$5 and if you match both numbers you receive \$500. It costs \$1 per play. Write a program that simulates playing the Lotto one million times. At the end of the simulation, print out the following:
1) The number of times exactly one number was matched.
2) The number of times exactly two numbers were matched.
3) The amount of money lost after buying the million lotto tickets.
For your simulation, you'll choose one winning lotto combination. Then, you'll simulate randomly choosing a million tickets, tallying up the winnings of each ticket.

Note: If you write the simulation properly, there is virtually no chance that you'll make money.

Sample Program Run:
You matched 1 number 64222 times.
You matched 2 numbers 1107 times.
You lost \$125390.

I have this so far:

```
import random

Match_One_Number = \$5
Match_Two_Numbers = \$500
Cost_Per_Play = \$1
MAX_LOTTO_NUM1 = 30
MAX_LOTTO_NUM2 = 60
NUM_LOTTO_TRIALS = 1000000

def main():

# Seed the random number generator.
random.seed()

count = 0
total = 0

# Run the game NUM_LOTTO_TRIALS times.
#

def playLotto():

# Get first Lotto number.
LOTTO_NUM1 = random.randint (1, MAX_LOTTO_NUM1)
# Get second Lotto number.
LOTTO_NUM2 = random.randint (31, MAX_LOTTO_NUM2)

```

Is This A Good Question/Topic? 0

## Replies To: Problem with how to use the program.

### #2 blackcompe

• D.I.C Lover

Reputation: 1158
• Posts: 2,538
• Joined: 05-May 05

## Re: Problem with how to use the program.

Posted 14 September 2012 - 09:19 PM

1. Ok, so you need to call playlotto in a loop and accumulate the winnings. So perhaps you could have playlotto return the money won or lost (negative number).
2. The directions said you to define two lottery picks for all drawings to be compared against. You need to do that, and in playlotto use the random numbers you generate to detect a match.

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}