yea, this is long.. but how do i make this repeat?
At the end it's suppose to ask "do you want to do this again, y for yes, n for no" where yes is repeat from the beginning and no is exit. I think i messed it up............................ someone help?

``````import random

print "Number of the day:"

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

y = dieroll() + dieroll()
return y

#main
print dieroll(), "+", dieroll(), "= [", z, "]"

print "-" *35
print

x2 = 2009 - x
return x2

#main

print
print "Hello", name
x =input("What year were you born?:")
print
print x, "-2009 =", x2
print "cool, you are", x2, "years old"

print
randomquestion=raw_input("so, do you like buying things?")

print
a=raw_input("What are 2 items that you bought this week?:")

x2 = x + 2.05
y2 = y + 2.05
return x2, y2

#main

x = input("how much did it cost ")
y = input("how about the other one?")
print
print x, " + 5%GST + 8%PST = ", x2
print y, " + 5%GST + 8%PST = ", y2
print "the total is: ", "\$", x2 + y2

def dieroll():
question=raw_input("Here are some lottery numbers you can use (press enter key):")
for each in range(6):
randomnumber = random.randrange(100)+1
print randomnumber

print
dieroll()
answer=raw_input("Do you want new numbers? (y or n)")

print "okay bye"
raw_input("\n\nPress the enter key to exit.")``````

The standard way of repeating code is to use a while loop. There are two styles: the 'test first' and 'test last' methods.

``````# a test-first loop: set the sentinel and repeat until sentinel is false

repeat = True
while repeat:
print "You lose!"
if raw_input("Play again? (y/n) ") == "n":
repeat = False``````
``````# a test-last method: repeat until the test fails.  This method makes more sense to me but is frowned on by some purists.

while True:
print "You lose!"
if raw_input("Play again? (y/n) ") == "n":
break``````

Jeff

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.