This time we'll work with meat tubers, or hot dogs.
class hotDog:
The attributes we will give the hot dog are how long we cooked the hot dog, if it's raw, medium, well-done, or burnt, and what condiments it has.
def __init__(self):
self.cookedLevel=0
self.cookedName="raw"
self.condiments=["no condiements"]
Yep, that's a pretty good tasting hot dog right there.
Well, it may not be cooked or have any condiments, but before we do anything, we should program the levels from raw meat to charcoal.
def cook(self, time):
self.cookedLevel=self.cookedLevel + time
if self.cookedLevel > 8:
self.cookedName="burnt & black"
elif self.cookedLevel > 5:
self.cookedName="perfect & pure"
elif self.cookedLevel > 3:
self.cookedName="a well wiener"
else:
self.cookedName="raw & repulsive"
There's our levels. Now, let's cook those dogs!
Here is the full program. The sleeping time parts are just so the words don't go by so quickly. Here is the full program:
import random, time
class hotDog:
def __init__(self):
self.cookedLevel=0
self.cookedName="raw"
self.condiments=["no condiments"]
def cook(self, time):
self.cookedLevel=self.cookedLevel + time
if self.cookedLevel > 8:
self.cookedName="burnt & black"
elif self.cookedLevel > 5:
self.cookedName="perfect & pure"
elif self.cookedLevel > 3:
self.cookedName="a well wiener"
else:
self.cookedName="raw & repulsive"
theDog=hotDog()
print("Your hot dog has been cooked for", theDog.cookedLevel, "minutes.")
time.sleep(3)
print("Your dog is", theDog.cookedName, ".")
time.sleep(3)
print("Your wiener has", theDog.condiments, ".")
time.sleep(2)
print("How about we cook the hot dog? I'll cook it for a random amount of time.")
time.sleep(3)
randomCookTime=random.randint(1, 9)
theDog.cook(randomCookTime)
time.sleep(randomCookTime)
print("I have cooked the weiner for", theDog.cookedLevel, "minutes.")
time.sleep(3)
print("The dog is now", theDog.cookedName, ".")
time.sleep(3)
print("Does it taste better?")
Alright! Save this in a new program, and run it. This is what I got:
Your hot dog has been cooked for 0 minutes.
Your dog is raw .
Your wiener has ['no condiments'] .
How about we cook the hot dog? I'll cook it for a random amount of time.
I have cooked the wiener for 7 minutes.
The dog is now perfect & pure .
Does it taste better?
You should get something like that (but you might get a different time at line 5 and a different title at line 6). But, we're not finished just yet! This hot dog has no condiments! Things are about to get trickier...
Here's the new and improved program:
import random, time
class hotDog:
def __init__(self):
self.cookedLevel=0
self.cookedName="raw"
self.condiments=["no condiments"]
def __str__(self):
msg="A hot dog"
if len(self.condiments) != "no condiments":
msg=msg + " with "
for i in self.condiments:
msg=msg+i+", "
msg=msg.strip(", ")
msg=self.cookedName + " " + msg + "."
return msg
def cook(self, time):
self.cookedLevel=self.cookedLevel + time
if self.cookedLevel > 8:
self.cookedName="burnt & black"
elif self.cookedLevel > 5:
self.cookedName="perfect & pure"
elif self.cookedLevel > 3:
self.cookedName="a well wiener"
else:
self.cookedName="raw & repulsive"
def addCondiment(self, condiment):
self.condiments.append(condiment)
theDog=hotDog()
print("Your hot dog has been cooked for", theDog.cookedLevel, "minutes.")
time.sleep(3)
print("Your dog is", theDog.cookedName, ".")
time.sleep(3)
print("Your wiener has", theDog.condiments, ".")
time.sleep(2)
print("How about we cook the hot dog? I'll cook it for a random amount of time.")
time.sleep(3)
condimentlist=["ketchup", "mustard", "relish", "mayonnaise"]
randomCondiments=random.randint(0, 3)
randomCookTime=random.randint(1, 9)
theDog.cook(randomCookTime)
time.sleep(randomCookTime)
print("I have cooked the weiner for", theDog.cookedLevel, "minutes.")
time.sleep(3)
print("The dog is now", theDog.cookedName, ".")
time.sleep(3)
print("Does it taste better?")
time.sleep(3)
print("Wait, we need condiments!")
time.sleep(3)
print("Let's cook another hot dog...")
theDog.cook(randomCookTime)
time.sleep(randomCookTime)
print("I have cooked another hot dog for", randomCookTime, "minutes.")
time.sleep(3)
print("So, that means the hot dog is", theDog.cookedName, ".")
time.sleep(3)
print("Now, perfect or not, let me put the condiments on it.")
time.sleep(3)
for i in range(randomCondiments):
theCondiment=i
if theCondiment==0:
theCondiment="ketchup"
elif theCondiment==1:
theCondiment="mustard"
elif theCondiment==2:
theCondiment="relish"
else:
theCondiment="mayonnaise"
print("Here are the condiments:")
time.sleep(3)
print(theCondiment)
There is really an easier way to explain this, but I'm going the creative way to make a fun hot dog program that doesn't do the same thing every time.
When I ran the program, I got this:
Your hot dog has been cooked for 0 minutes.
Your dog is raw .
Your wiener has ['no condiments'] .
How about we cook the hot dog? I'll cook it for a random amount of time.
I have cooked the weiner for 6 minutes.
The dog is now perfect & pure .
Does it taste better?
Wait, we need condiments!
Let's cook another hot dog...
I have cooked another hot dog for 6 minutes.
So, that means the hot dog is burnt & black .
Now, perfect or not, let me put the condiments on it.
Here are the condiments:
ketchup
Ta-da! Wait...
When the hot dog was cooked for 6 minutes, it was perfect & pure. I get that, but there's one problem that happened here...
The wiener was cooked for the same amount of time, and the hot dog ended up burnt & black!
This article's been going on a bit too long. We'll do some debugging next time!