June 2017
Beginner
320 pages
7h 37m
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.
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.")1112 if how_much < 50:13 print("Nice, you're not greedy, you win!")14 exit(0)15 else:16 dead("You greedy bastard!")171819 def bear_room():20 print("There is a bear here.")21 ...
Read now
Unlock full access