我想要一个只对探索和狩猎选项计1圈的回合计数器。再加上现在的年龄。我该怎么做?我使用的是python2.7。以下是代码的重要部分:
from main import name
import os
import random
kenyan_sand_boa = {
"snek": "kenyan sand boa",
"prey": "mice, " "birds, " "lizards",
"biome": "desert",
"predators": "desert monitor lizard",
"adult age": 156,
"baby size": 10,
"adult size": 20,
"current size": 10,
"current age": "0",
"name": name,
}
os.system('cls')
def menu():
os.system('cls')
print '''Now that you have chosen what snek to be, you have a couple
options
1. Read info about kenyan sand boas.
2. Explore.
3. Hunt.
4. View inventory.
5. Save.
6. Exit.
'''
loop = 1
choice = 0
while loop == 1:
menu()
choice = int(raw_input())
if choice == 1:
#information about kenyan sand boas
if choice == 2:
#exploring
if choice == 3:
#huntinng
if choice == 4:
#view inventory
else:
menu()
初始化
turn=0
在探索/狩猎案例中,添加以下内容:
可能必须将age定义为int,因为它当前是一个字符串,但一旦您这样做,此代码将完成任务。你知道吗
在
while
代码集中,将其设置为0。你知道吗因为你也在增加年龄,所以最好把
"current age"
设为0
,而不是"0"
。 在狩猎和探索if
子句中,按1递增"current age"
和turn
。(改用elif
会更像Python)相关问题 更多 >
编程相关推荐