February 2024
Beginner
352 pages
8h 16m
English
You have learned if-statements, functions, and lists. Now it’s time to bend your mind. Type this in, and see if you can figure out what it’s doing:
Listing 35.1: ex35.py
1 from sys import exit
2
3 def gold_room():
4 print("This room is full of gold. How much do you take?")
5
6 choice = input("> ")
7 if "0" in choice or "1" in choice:
8 how_much = int(choice)
9 else:
10 dead("Man, learn to type a number.")
11
12 if how_much < 50:
13 print("Nice, you're not greedy, you win!")
14 exit(0)
15 else:
16 dead("You greedy bastard!")
17
18
19 def bear_room():
20 print("There is a bear here.")
21 print("The bear has a bunch of honey.")
22 print("The fat bear is in front of another door." ...Read now
Unlock full access