我刚刚开始使用Python创建自己的计算机游戏.这是第3章的示例代码:
1 # This is a Guess the Number game.
2 import random
3
4 guessesTaken = 0
5
6 print('Hello! What is your name?')
7 myName = input()
8
9 number = random.randint(1, 20)
10 print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
11
12 for guessesTaken in range(6):
13 print('Take a guess.') # Four spaces in front of "print"
14 guess = input()
15 guess = int(guess)
16 …Run Code Online (Sandbox Code Playgroud) python ×1