Advanced Mash: I'm stuck

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2009
Posts: 87
Reputation: Norbert X is an unknown quantity at this point 
Solved Threads: 0
Norbert X's Avatar
Norbert X Norbert X is offline Offline
Junior Poster in Training

Advanced Mash: I'm stuck

 
0
  #1
Feb 27th, 2009
I've been racking my brain on this problem for like 2 hours. The thing I have to do here is use one single random function for the entire MASH program instead of the usual 4. The problem is, when I get a result, they're all from catagory 1 (married to girl1, driving a car1 living in house1, etc.) How can I get different results? Here's what I have so far:

  1. import random
  2.  
  3. house = ["a mansion", "an apartment", "a shack", "a house"]
  4. spouse = ["name1", "name2", "name3", "name4"]
  5. car = ["car1", "car2", "car3", "car4"]
  6. kids = ["no kids", "1 kid", "2 kids", "5 kids"]
  7.  
  8. print"List 3 people you want to marry in the future:"
  9. spouse[0] = raw_input("1. ")
  10. spouse[1] = raw_input("2. ")
  11. spouse[2] = raw_input("3. ")
  12.  
  13. print"List 1 person who you don't like: "
  14. spouse[3] = raw_input("1. ")
  15.  
  16. print"List 3 cars you want in the future:"
  17. car[0] = raw_input("1. ")
  18. car[1] = raw_input("2. ")
  19. car[2] = raw_input("3. ")
  20.  
  21. print"List 1 car that you don't like: "
  22. car[3] = raw_input("1. ")
  23.  
  24.  
  25. #main
  26. while True:
  27. z = random.randrange(3)
  28. b = z
  29. raw_input("Now mashing... Press [enter] for your results")
  30. print "You will live in",house[b]
  31. print "Married to",spouse[b]
  32. print "Driving a",car[b]
  33. print "With",kids[b],"running around the house"
  34. choice = raw_input("Do you want a second chance? Type [n] to quit. ")
  35. if"n"in choice:
  36. break
  37.  
  38. raw_input("Press [Enter] to exit.")

The main problem is b and z. I can't figure it out. Could some one help me?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 950
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 147
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Advanced Mash: I'm stuck

 
0
  #2
Feb 27th, 2009
Well if you want them to all be in a different category then you have to get a new number each time. Also you can use random.choice() to get a random choice from a list.

Here is what i would do
  1. import random
  2.  
  3. house = ["a mansion", "an apartment", "a shack", "a house"]
  4. spouse = ["name1", "name2", "name3", "name4"]
  5. car = ["car1", "car2", "car3", "car4"]
  6. kids = ["no kids", "1 kid", "2 kids", "5 kids"]
  7.  
  8. print"List 3 people you want to marry in the future:"
  9. spouse[0] = raw_input("1. ")
  10. spouse[1] = raw_input("2. ")
  11. spouse[2] = raw_input("3. ")
  12.  
  13. print"List 1 person who you don't like: "
  14. spouse[3] = raw_input("1. ")
  15.  
  16. print"List 3 cars you want in the future:"
  17. car[0] = raw_input("1. ")
  18. car[1] = raw_input("2. ")
  19. car[2] = raw_input("3. ")
  20.  
  21. print"List 1 car that you don't like: "
  22. car[3] = raw_input("1. ")
  23.  
  24.  
  25. #main
  26. while True:
  27. raw_input("Now mashing... Press [enter] for your results")
  28. print "You will live in",random.choice(house)
  29. print "Married to",random.choice(spouse)
  30. print "Driving a",random.choice(car)
  31. print "With",random.choice(kids),"running around the house"
  32. choice = raw_input("Do you want a second chance? Type [n] to quit. ")
  33. if"n"in choice:
  34. break
  35.  
  36. raw_input("Press [Enter] to exit.")
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum


Views: 253 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC