| | |
Advanced Mash: I'm stuck
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
The main problem is b and z. I can't figure it out. Could some one help me?
python Syntax (Toggle Plain Text)
import random house = ["a mansion", "an apartment", "a shack", "a house"] spouse = ["name1", "name2", "name3", "name4"] car = ["car1", "car2", "car3", "car4"] kids = ["no kids", "1 kid", "2 kids", "5 kids"] print"List 3 people you want to marry in the future:" spouse[0] = raw_input("1. ") spouse[1] = raw_input("2. ") spouse[2] = raw_input("3. ") print"List 1 person who you don't like: " spouse[3] = raw_input("1. ") print"List 3 cars you want in the future:" car[0] = raw_input("1. ") car[1] = raw_input("2. ") car[2] = raw_input("3. ") print"List 1 car that you don't like: " car[3] = raw_input("1. ") #main while True: z = random.randrange(3) b = z raw_input("Now mashing... Press [enter] for your results") print "You will live in",house[b] print "Married to",spouse[b] print "Driving a",car[b] print "With",kids[b],"running around the house" choice = raw_input("Do you want a second chance? Type [n] to quit. ") if"n"in choice: break raw_input("Press [Enter] to exit.")
The main problem is b and z. I can't figure it out. Could some one help me?
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
Here is what i would do
python Syntax (Toggle Plain Text)
import random house = ["a mansion", "an apartment", "a shack", "a house"] spouse = ["name1", "name2", "name3", "name4"] car = ["car1", "car2", "car3", "car4"] kids = ["no kids", "1 kid", "2 kids", "5 kids"] print"List 3 people you want to marry in the future:" spouse[0] = raw_input("1. ") spouse[1] = raw_input("2. ") spouse[2] = raw_input("3. ") print"List 1 person who you don't like: " spouse[3] = raw_input("1. ") print"List 3 cars you want in the future:" car[0] = raw_input("1. ") car[1] = raw_input("2. ") car[2] = raw_input("3. ") print"List 1 car that you don't like: " car[3] = raw_input("1. ") #main while True: raw_input("Now mashing... Press [enter] for your results") print "You will live in",random.choice(house) print "Married to",random.choice(spouse) print "Driving a",random.choice(car) print "With",random.choice(kids),"running around the house" choice = raw_input("Do you want a second chance? Type [n] to quit. ") if"n"in choice: break 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
Check out my Site | and join us on IRC | Python Specific IRC
![]() |
Other Threads in the Python Forum
- Previous Thread: how do i make this repeat? >.>
- Next Thread: What are the .apy files in Python
Views: 253 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython





