# For Loop Price guessing game

Page 1 of 1

## 3 Replies - 3083 Views - Last Post: 23 February 2011 - 12:27 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=217293&amp;s=942e554e9cda468cc8b4ee2736443daf&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ma1767

Reputation: 0
• Posts: 2
• Joined: 19-February 11

# For Loop Price guessing game

Posted 19 February 2011 - 02:07 PM

Hey Guys,

I am in desperate need of help on my hw assignment. Below is the problem:

Using a 'for' loop, write a price guessing game that satisfies the following criteria.
Your program should store the name of the prize and the price of that prize in
variables/constants that you specify. Ask the user how many contestants there are and
store this in another variable. Use the number of contestants as your for loop range.
Using your for loop get input from each user as their guess for the price of the prize.
After all users have guessed the price, print out which contestant won the prize. The
winner is the person who is closest to the price without going over. If two users enter
the same price, the first contestant wins the prize.
Sample input/output would look like something like (user input in italics):
The Right Price!
---------------------------
The prize is: A new car!
How many players are there? 5
Contestant #1, What is your wager (in dollars): \$12300
Contestant #2, What is your wager (in dollars): \$21000
Contestant #3, What is your wager (in dollars): \$12301
Contestant #4, What is your wager (in dollars): \$1
Contestant #5, What is your wager (in dollars): \$17500
The price of this prize was: \$17490
Contestant #3 wins!
_______________________________________________

This is what i have so far but i don't know where to go from here.

```print('The Right Price!')
print('--------------------------')
print('The Prize is a New Car!')

price = 1000

total = 0
players = int(input('How many players are there? '))
for i in range(players):
con = (input('Contestant #' + str(i + 1) +
', What is your wager (in dollars) '))

print('The price of the prize was: ' + str(price) + '!')

```

Anything would be helpful at this point. Thanks guys!

MOD EDIT: When posting code...USE CODE TAGS!!!

This post has been edited by JackOfAllTrades: 19 February 2011 - 03:18 PM

Is This A Good Question/Topic? 0

## Replies To: For Loop Price guessing game

### #2 baavgai

• Dreaming Coder

Reputation: 7163
• Posts: 14,929
• Joined: 16-October 07

## Re: For Loop Price guessing game

Posted 19 February 2011 - 05:16 PM

You seem to have the basics of it...

You need to translate that input to int. Compare it to the target price. If it's closer than the last value entered, store the contestant number and what that contestant entered.

### #3 ma1767

Reputation: 0
• Posts: 2
• Joined: 19-February 11

## Re: For Loop Price guessing game

Posted 20 February 2011 - 07:39 AM

baavgai, on 19 February 2011 - 05:16 PM, said:

You seem to have the basics of it...

You need to translate that input to int. Compare it to the target price. If it's closer than the last value entered, store the contestant number and what that contestant entered.

Can you show me in code? Im a beginner so I'm not sure if I understand what you're saying 100%...

Thanks!

### #4 atraub

• Pythoneer

Reputation: 828
• Posts: 2,236
• Joined: 23-December 08

## Re: For Loop Price guessing game

Posted 23 February 2011 - 12:27 PM

What is suppose to happen if everyone guesses too high? This will affect your algorithm.

This post has been edited by atraub: 23 February 2011 - 12:28 PM