import time
import random
inventory = [""]
gold = 0
fish1 = "Mackarel"
fish2 = "Cod"
fish3 = "Salmon"
fish4 = "Herring"
fish5 = "Tuna"
trash1 = "Old Shoe"
trash2 = "Plastic Bag"
trash3 = "Rusted Empty Box"
trash4 = "Plank Fragment"
special1 = "Ring"
fish1_range = range(1,3)
fish2_range = range(3,5)
fish3_range = range(5,7)
fish4_range = range(7,9)
fish5_range = range(9,11)
trash1_range = range(11,16)
trash2_range = range(16,21)
trash3_range = range(21,26)
trash4_range = range(26,31)
special1_range = range(31,32)
print "~~~~WELCOME TO FISHING~~~~"
time.sleep(2)
print "Loading Version 0.2 ..."
time.sleep(2)
print "In this current version the last item in your inventory is sold."
print "To execute another function, for example fish twice you have to wait 20 seconds"
print "This means at the start it will take 20 seconds to load aswell."
def action_function(): #defining action start
action_function()
chance = random.randrange(1,31)
action = raw_input("Do you want to .sell or .fish?")
if action == "sell":
if inventory.index(1) == fish1:
inventory.pop(1)
gold + 5
print "You have sold a Mackarel for 5 gold coins!"
action_function()
if inventory.index(1) == fish2:
inventory.pop(1)
gold + 5
print "You have sold a Cod for 5 gold coins!"
action_function()
if inventory.index(1) == fish3:
inventory.pop(1)
gold + 5
print "You have sold a Salmon for 5 gold coins!"
action_function()
if inventory.index(1) == fish4:
inventory.pop(1)
gold + 5
print "You have sold a Herring for 5 gold coins!"
action_function()
if inventory.index(1) == fish5:
inventory.pop(1)
gold + 5
print "You have sold a Tuna for 5 gold coins!"
action_function()
if inventory.index(1) == trash1:
inventory.pop(1)
gold + 1
print "You have recycled an Old Shoe for 1 gold coin."
action_function()
if inventory.index(1) == trash2:
inventory.pop(1)
gold + 1
print "You have recycled an Plastic Bag for 1 gold coin."
action_function()
if inventory.index(1) == trash3:
inventory.pop(1)
gold + 1
print "You have recycled an Rusted Empty Box for 1 gold coin."
action_function()
if inventory.index(1) == trash4:
inventory.pop(1)
gold + 1
print "You have recycled an Old Shoe for 1 gold coin."
action_function()
if inventory.index(1) == special1:
inventory.pop(1)
gold + 10
print "A rare find, 10 gold pieces will serve you!"
action_function()
if action == "fish":
if random.randrange == fish1_range:
inventory.append(fish1)
print "You have reeled in a Mackarel!"
action_function()
if random.randrange == fish2_range:
inventory.append(fish2)
print "You have reeled in a Cod!"
action_function()
if random.randrange == fish3_range:
inventory.append(fish3)
print "You have reeled in a Salmon!"
action_function()
if random.randrange == fish4_range:
inventory.append(fish4)
print "You have reeled in a Herring!"
action_function()
if random.randrange == fish5_range:
inventory.append(fish5)
print "You have reeled in a Tuna!"
action_function()
if random.randrange == trash1_range:
inventory.append(trash1)
print "You have reeled in a...Shoe..."
action_function()
if random.randrange == trash2_range:
inventory.append(trash2)
print "You have reeled in a...Plastic Bag..."
action_function()
if random.randrange == trash3_range:
inventory.append(trash3)
print "You have reeled in a...Rusted Empty Box..."
action_function()
if random.randrange == trash4_range:
inventory.append(trash4)
print "You have reeled in a...Plank Fragment..."
action_function()
if random.randrange == special1_range:
inventory.append(special1)
print "You find a slightly dirty ring, after clearing the dirt it appears quite nice."
action_function()
if action == "inventory":
print inventory
action_function()
所以我现在已经尝试了数百次,我尝试使用循环和大量其他东西,但似乎没有任何东西可以按照我的意愿工作。大多数时候,当我定义一个函数时,它只是在第一部分之后变成空白,它可能会走得更远,但我不知道。另外,正如您从这个尴尬的问题中可以看出的那样,我是编程新手,请帮助我,如果有人能解释为什么它只打印到动作函数定义的文本。