Simple question
Dag Hansteen
d-hanst at online.no
Sun Jul 11 09:27:35 EDT 2004
#This is how you can do it:
# Answering 2 for "no" 10 times it will print "I want a cookie"
# and then print "Now the program will restart"
# then restarts.. :)
print "I want a cookie!"
class CookieProgram:
def __init__(self):
self.y = 10
def giveCookieOrNot(self):
while self.y == 0:
print "I want a cookie!"
self.y = 10
print "Now the program will restart."
self.giveCookieOrNot()
print
print "Give a cookie?"
print "1 Yes"
print "2 No"
print
gave = input("> ")
if gave == 1:
print "Thank you! That is much better."
else:
self.y = self.y - 1
self.giveCookieOrNot()
cookie = CookieProgram()
cookie.giveCookieOrNot()
# Best regards Dag Hansteen
----- Original Message -----
From: "wasian_god" <wasian_god at yahoo.com>
To: <python-list at python.org>
Sent: Saturday, July 10, 2004 11:49 AM
Subject: Simple question
> yea im knew to python, and i kno this is a very simple question. im
> trying to make a shell dat first says I want a cookie. Then it waits
> for the user to input the word cookie. while cookie is not inputted
> a timer counts down and at the end it prints out I want a cookie
> again. The timer then gets shorter. Heres what i have so far...
>
> print "I want a cookie!"
>
> m = 10
> y = m
> gave = 0
>
> if y == 0:
> print "I want a cookie!"
> m = m-1
> y = m
>
> if gave == 1:
> print "Thank you! That is much better."
> else:
> y = y-1
>
> I have tried a lot of other stuff so dont think this is what i
> started out with. but this is what i have now, any help would be
> appreciated so i can start gettin this whole "programming" stuff
> down.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
More information about the Python-list
mailing list