This is program i made (basic mash);
I want to make it so that the program will ask if you want to repeat it again. "n" = exit. and anything else makes it repeat.....can someone help me? I'm not sure how to do it ...

x = 0 

import random

house =["Mansion", "Apartment", "Shack", "House"]
spouse =["EMPTY", "EMPTY", "EMPTY", "EMPTY"]
car =["EMPTY", "EMPTY", "EMPTY", "EMPTY"]
def dieroll():
    randomnumber = random.randrange(10)+1
    return randomnumber

print "Enter the name of three people you could marry: "
name1 = raw_input("Name1: ")
spouse[0]= name1
name2 = raw_input("Name2: ")
spouse[1]= name2
name5 = raw_input("Name3: ")
spouse[2]= name5

print "Enter the name of one person you wouldn't want to marry:"
name4 =raw_input("Name4: ")
spouse[3]= name4

print "Enter the name of 3 cars you want: "
car1 =raw_input("car1: ")
car[0]= car1
car2 = raw_input("car2: ")
car[1] = car2
car3=raw_input("car3: ")
car[2]=car3
print "Enter the name of one car you don't want: "
car4 =raw_input("car4: ")
car[3]=car4

#Results
print
print
print "You will live in a", random.choice(house)
print "Married to", random.choice(spouse)
print "While driving your", random.choice(car) 
print "With your", dieroll(), "kids in it!"

raw_input("\nPress the Enter key to continue")

Generally you use a while loop you can break out of when done. I would use functions and pass arguments to streamline your code:

# random_game.py

import random

def dieroll():
    randomnumber = random.randrange(10)+1
    return randomnumber

def get_spouse(spouse):
    print "Enter the name of three people you could marry: "
    name1 = raw_input("Name1: ")
    spouse[0]= name1
    name2 = raw_input("Name2: ")
    spouse[1]= name2
    name5 = raw_input("Name3: ")
    spouse[2]= name5
    print "Enter the name of one person you wouldn't want to marry:"
    name4 =raw_input("Name4: ")
    spouse[3]= name4
    return spouse

def get_car(car):
    print "Enter the name of 3 cars you want: "
    car1 =raw_input("car1: ")
    car[0]= car1
    car2 = raw_input("car2: ")
    car[1] = car2
    car3=raw_input("car3: ")
    car[2]=car3
    print "Enter the name of one car you don't want: "
    car4 =raw_input("car4: ")
    car[3]=car4
    return car

def show_result(house, spouse, car):
    print
    print
    print "You will live in a", random.choice(house)
    print "Married to", random.choice(spouse)
    print "While driving your", random.choice(car) 
    print "With your", dieroll(), "kids in it!"
    print
    more = raw_input("Any more (yes or no)? ")
    return more.lower()

house = ["Mansion", "Apartment", "Shack", "House"]
spouse = ["EMPTY", "EMPTY", "EMPTY", "EMPTY"]
car = ["EMPTY", "EMPTY", "EMPTY", "EMPTY"]

while True:
    spouse = get_spouse(spouse)
    car = get_car(car)
    more = show_result(house, spouse, car)
    # the while loop will continue until you break out
    if 'n' in more:
        break
    print

print "Thanks for playing!"
raw_input("Press the Enter key to quit .. ")

But if you do really want to keep it in the procedure you have now, then os.startfile is what you need to look at.

#at the end of your code you put something like this
os.starfile(os.getcwd()+"\\Name of Python File.py")
#that will re-start your python file.

Yo. I've made a MASH thing as well. Try this one:

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. ")

w = random.randrange(3)
x = random.randrange(3)
y = random.randrange(3)
z = random.randrange(3)

raw_input("Now mashing... Press [enter] for your results")
print "You will live in",house[w]
print "Married to",spouse[x]
print "Driving a",car[y]
print "With",kids[z],"running around the house"

raw_input("Press [Enter] to exit.")

You just need to use randoms like this.

lol, wow nice. Yours so much smaller than mine.

ahhhhhh I seee.... thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.