mayonnaise
mayonnaise
mayonnaise
Here are the condiments:
[ERROR]
Let's see how we can fix this... Well, first, we can try doing 2 other variables. randomCooktime2 and randomCooktime3. Let's also add in another list, so now our condiment section looks like this:
condimentlist=["ketchup", "mustard", "relish", "mayonnaise"] #Used for randomCondiments
condimentlist2=["ketchup", "mustard", "relish", "mayonnaise", " "] #Used for randomCondiments 2 and randomCondiments 3
randomCondiments=random.randint(0, 3)
randomCondiments2=random.randint(0, 4)
randomCondiments3=random.randint(0, 4)
Yes, I used the comments, because finding everything was getting confusing. Now, let's work our magic with the other condiments!
print("Here are the condiments:")
time.sleep(3)
#The first condiment
if randomCondiments == 0:
print(condimentlist[randomCondiments])
elif randomCondiments == 1:
print(condimentlist[randomCondiments])
elif randomCondiments == 2:
print(condimentlist[randomCondiments])
elif randomCondiments == 3:
print(condimentlist[randomCondiments])
#The second condiment
if randomCondiments2 == 0:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 1:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 2:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 3:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 4:
print(condimentlist2[randomCondiments2])
#The third condiment
if randomCondiments3 == 0:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 1:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 2:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 3:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 4:
print(condimentlist2[randomCondiments3])
time.sleep(2)
print("Now our hot dog is complete!")
Now, run the program. It should do something like 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 5 minutes.
The dog is now a well wiener .
Does it taste better?
Wait, we need condiments!
Let's cook another hot dog...
I have cooked another hot dog for 9 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:
mustard
mustard
mayonnaise
Now our hot dog is complete!
Well, we got mustard twice. Debugging is obviously very difficult, so we can just say you got extra mustard. But if you want to make it so it never says the same condiment twice, we'll get into things so difficult I might not even be able to state them.
So, our final program has come out like this:
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"] #Used for randomCondiments
condimentlist2=["ketchup", "mustard", "relish", "mayonnaise", " "] #Used for randomCondiments 2 and randomCondiments 3
randomCondiments=random.randint(0, 3)
randomCondiments2=random.randint(0, 4)
randomCondiments3=random.randint(0, 4)
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...")
randomCookTime2=random.randint(1, 9)
theDog.cook(randomCookTime2)
time.sleep(randomCookTime2)
print("I have cooked another hot dog for", randomCookTime2, "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)
print("Here are the condiments:")
time.sleep(3)
#The first condiment
if randomCondiments == 0:
print(condimentlist[randomCondiments])
elif randomCondiments == 1:
print(condimentlist[randomCondiments])
elif randomCondiments == 2:
print(condimentlist[randomCondiments])
elif randomCondiments == 3:
print(condimentlist[randomCondiments])
#The second condiment
if randomCondiments2 == 0:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 1:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 2:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 3:
print(condimentlist2[randomCondiments2])
elif randomCondiments2 == 4:
print(condimentlist2[randomCondiments2])
#The third condiment
if randomCondiments3 == 0:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 1:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 2:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 3:
print(condimentlist2[randomCondiments3])
elif randomCondiments3 == 4:
print(condimentlist2[randomCondiments3])
time.sleep(2)
print("Now our hot dog is complete!")
I actually think some lines in this program are never used... Oh well.
That's it for this article. I challenge you to see if the block of code that begins with def __str__(self): really is pointless!
Also, if you look in that block of code, you will see a function known as len(). What does this one mean?
No comments:
Post a Comment