Exercise 35 - Triggering other Prompts?

Hello, I just typed my code for Exercise 36 (found here: https://pastebin.com/7bLNRq3q)

The first thing I noticed is in the gold_room(): https://pastebin.com/PSqLAk2M

How can you get over 1? You only trigger the “Nice, your not greedy, you win!” when you type 0 or 1 but anything above and you get “Man, learn to type a number” even though “how_much” is set to less than 50

My next question is about the bear area. This part: https://pastebin.com/zfKrGRm7

We never get to the “The bear gets pissed off and chews your leg off.”. Is that by design ?

This is a subset of the full code. You are right, the if-statement only handles 0, 1 or else.

This is setting you up for more code later. Keep going.

Yea i see, in Study Drill 5, i had to make it detect a regular string (full answer here: https://pastebin.com/EDEyc3HR )

One last question though. There is a “While True” loop (found on line 25 on the first pastebin in my code). Why do we need to make an infinite loop?

You need an infinite loop here because you don’t know how many loops you need in advance.

1 Like

One thing you can do @MilkTaste01 is try out what you think the code should do. For example, if you think it should not use an infinite loop, then try to change it to not use one. You might come up with something better, and if not you’ll find out why I did it.

Thank you Zed.

I do get why we need the infinite loop. When we navigate through the bear room, we need to taunt the bear and then open the door which gets us to the gold room. However, when we remove the “while true” loop, after we taunt the bear, it ends the script.

1 Like

reason behind making while loop true is that when first time loop runs it is asking for the action which you want to perform to move bear from another door. so as you give your input “taunt bear” this will set the overall condition of elif to true and and executes the block and also set the flag bear_moved to true.

in loop one condition became true so other condition will not be tested and loop will run aging as it is infinite so now this time you are giving your input as “open door” and this time the flag bear_moved is already true so overall condition of elif will also get true and you will redirected to gold_room() function

you can also do nesting like making another function for third room and calling in if statement