3 Replies - 1917 Views - Last Post: 23 February 2011 - 12:27 PM Rate Topic: -----

#1 ma1767  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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!!!

:code:

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  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5832
  • View blog
  • Posts: 12,683
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 ma1767  Icon User is offline

  • New D.I.C Head

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

Re: For Loop Price guessing game

Posted 20 February 2011 - 07:39 AM

View Postbaavgai, 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!
Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1