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

def add2dieroll():
    y = dieroll() + dieroll()
    return y

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

print "-" *35
print

name=raw_input("Hello,what is your name?")

def addyear(x):
    x2 = 2009 - x
    return x2

#main

print
print "Hello", name
x =input("What year were you born?:")
x2 = addyear(x)
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?:")

def add2sub2(x,y):
    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
x2, y2 = add2sub2(x,y)
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
answer = 'y'
while answer == 'y':
    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.