Alright, let's recap. We wrote a new article called Wieners.py (at least, that's what I named it), but...
I have cooked the wiener for 6 minutes.
The dog is now perfect & pure .
And then...
I have cooked another hot dog for 6 minutes.
So, that means the hot dog is burnt & black .
If the dog was cooked for 6 minutes, it shouldn't be burnt & black! That's a bad sign. Well, looks like it's time to do some debugging!
For the oblivious, a bug is not a real bug in the program. It's a problem with the program. So, to get rid of that bug is called debugging.
Alright, as I thought about it, I realized that once randomCookTime has chosen a random number, it keeps that number. But why did the status change? Well... I honestly don't know, but I'm guessing that it did choose a different number, it just didn't display it. So, how do we fix this? My first plan is to do randomCookTime=randomCookTime.
print("Wait, we need condiments!")
time.sleep(3)
print("Let's cook another hot dog...")
randomCookTime=randomCookTime
theDog.cook(randomCookTime)
time.sleep(randomCookTime)
print("I have cooked another hot dog for", randomCookTime, "minutes.")
Will that work? Let's just see:
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 1 minutes.
The dog is now raw & repulsive .
Does it taste better?
Wait, we need condiments!
Let's cook another hot dog...
I have cooked another hot dog for 1 minutes.
So, that means the hot dog is raw & repulsive .
Now, perfect or not, let me put the condiments on it.
Traceback (most recent call last):
File "C:\Python33\Wieners.py", line 69, in <module>
if theCondiment==0:
NameError: name 'theCondiment' is not defined
Oh no! randomCookTime=randomCookTime broke the condiments! But do we give up? No! Never! I didn't expect this kind of error to happen, but I anticipated this to not work. I have a backup plan: randomCookTime2.
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.")
Will this work? I hope so, this is my only backup plan.
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 3 minutes.
The dog is now raw & repulsive .
Does it taste better?
Wait, we need condiments!
Let's cook another hot dog...
I have cooked another hot dog for 7 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:
relish
Success! But, we still face one problem.
Only one condiment ends up on the list. What if we want 2, 3, or all the condiments? This is where things get more complicated.
Plan A is... I got it, we have to do 3 ranges!
print("Now, perfect or not, let me put the condiments on it.")
time.sleep(3)
if randomCondiments == 1:
for i in range(0, 1):
print(condimentlist[randomCondiments])
if randomCondiments == 2:
for i in range(0, 2):
print(condimentlist[randomCondiments])
if randomCondiments == 3:
for i in range(0, 3):
print(condimentlist[randomCondiments])
if randomCondiments == 4:
for i in range(0, 4):
print(condimentlist[randomCondiments])
print("Here are the condiments:")
Will this work? We'll just see.
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 4 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.
mayonnaise
mayonnaise
mayonnaise
Here are the condiments:
Traceback (most recent call last):
File "C:\Python33\Wieners.py", line 81, in <module>
print(theCondiment)
NameError: name 'theCondiment' is not defined
That's a bad sign. This article has gone on long enough. We'll have to fix our mayonnaise next time!
No comments:
Post a Comment