这可能是一个微不足道的忽视,刚开始使用python

时间:2011-12-06 00:23:18

标签: python if-statement

我为我的人类体育课做了关于肝脏的短文冒险。

link:http://pastebin.com/QYkn5VuU

#SUPER LIVER ADVENTURE 12!

from sys import exit 
from random import randint 

quips = ["Welcome!",
"have a wonderful day", 
"Livers are cool!", 
"this text was chosen at random", 
"Writen in python", 
"woo, splash text!", 
"Notch loves ez!", 
"Almost dragon free!"]

print quips [randint (0, len(quips) -1)] 

def first_thing () :
    print "You are a liver, congratulations! You should do some liver stuff now."
    print "Here comes some blood, what should you do?"
    filterblood = raw_input (">")

    if filterblood == "filter" or "filter blood" or "filter the blood":
        return 'second_thing'

    elif filterblood == "who cares":
        print "I care, be more considorate!" 
        return "first_thing" 

    else: 
        print "Sorry, no (Hint, it is your main purpose!)"   
        return "first_thing" 

def second_thing () :
    print "You are now filtering the blood, good for you!"
    print "oh no! There is too much aldosterone! what would that do?" 
    fluidz = raw_input (">")

    if fluidz == "fluid retension" or "Keeping fluids": 
        return 'third_thing'

    else: 
        print "nope! (hint, what does aldosterone do?)"
        return "second_thing"

def third_thing () :
    print "Oh no!, that's bad!"
    print "What should you do about that aldosterone?" 
    metabolize = raw_input (">")

    if metabolize == "metabolize" :
        return 'fourth_thing'

    else: 
        print "BRZZZZ, wrong!" 
        return "third_thing"

def fourth_thing () :
    print "super duper!" 
    print "the aldosterone has been taken care of, no problems at the current moment"
    print "..."
    print "..."
    print "..."
    print "After a couple of months a problem arises, you are inflamed, what could this be?"
    hepatitis = raw_input (">")

    if hepatitis == "hepatitis": 
        return 'fifth_thing'

    else:
        return "fourth_thing"

def fifth_thing () :
    print "OH NO! Hepatitis!"
    print "What could have caused this?"
    idunno_somthing = raw_input (">")

    if idunno_somthing == "infection" or "an infection" :
        print "neat, thats no good."
        print "thank you for coming"
        exit (0)

    elif idunno_somthing == "sex" or "drugs" or "rock n roll":
        print "very funny, what specificly caused it?"
        return "fifth_thing"

    else:
        return "fifth_thing" 


ROOMS = {
    'first_thing': first_thing, 
    'second_thing': second_thing, 
    'third_thing': third_thing, 
    'fourth_thing': fourth_thing, 
    'fifth_thing': fifth_thing
}

def runner(map, start): 
    next = start
    while True:
        room = map[next]
        print "\n--------" 
        next = room()

runner(ROOMS, 'first_thing')

#if you steal my stuff, credit me. 

我不得不两次输入肝炎(第66和67行),并且没有一个人工作过。

编辑:我错过了什么?

这可能是一个非常愚蠢的问题,我刚刚开始。我们都是初学者。

3 个答案:

答案 0 :(得分:6)

第82行的elif语句为:

elif idunno_something == "sex" or "drugs" or "rock n roll":

这应该是

elif idunno_something in ("sex", "drugs", "rock n roll"):

同样的改变应该有助于第22,38和77行。

答案 1 :(得分:2)

由于您是初学者,我将从寻求帮助的一些建议开始。理想情况下,您希望提供尽可能少的代码来显示您遇到的问题。解释您期望发生的事情,以及执行您提供的代码时实际发生的情况。

如果要检查字符串是否为多个值,可以将可能的值放在列表或元组中。

if filterblood in ["filter", "filter blood", "filter the blood"]:

在上述示例的情况下,您可能希望接受以“过滤器”开头的所有答案:

if filterblood.startswith("filter"):

答案 2 :(得分:2)

为了好玩,我完全修复了你的程序。

#!/usr/bin/python
# SUPER LIVER ADVENTURE 12!
# If you steal my stuff, credit me.
# Owen Sanders on StackOverflow
#
# Updated December 5, 2011
# OregonTrail on StackOverflow

from sys import exit
from random import randint

quips = [
    "Welcome!",
    "have a wonderful day",
    "Livers are cool!",
    "this text was chosen at random",
    "Writen in python",
    "woo, splash text!",
    "Notch loves ez!",
    "Almost dragon free!"
]

print quips[randint(0, len(quips)-1)]

def first_thing():
    print ("You are a liver, congratulations! "
           "You should do some liver stuff now.")
    print "Here comes some blood, what should you do?"
    filterblood = raw_input ("> ")

    if filterblood in ("filter", "filter blood", "filter the blood"):
        return 'second_thing'

    elif filterblood == "who cares":
        print "I care, be more considorate!"
        return "first_thing"

    else:
        print "Sorry, no (Hint, it is your main purpose!)"
        return "first_thing"

def second_thing():
    print "You are now filtering the blood, good for you!"
    print "oh no! There is too much aldosterone! what would that do?"
    fluidz = raw_input ("> ")

    if fluidz in ("retain fluid", "fluid retention", "keep fluids",
                  "keep fluid"):
        return 'third_thing'

    else:
        print "nope! (hint, what does aldosterone do?)"
        return "second_thing"

def third_thing():
    print "Oh no!, that's bad!"
    print "What should you do about that aldosterone?"
    metabolize = raw_input ("> ")

    if metabolize == "metabolize":
        return 'fourth_thing'

    else:
        print "BRZZZZ, wrong!"
        return "third_thing"

def fourth_thing():
    print "super duper!"
    print ("the aldosterone has been taken care of, no problems at the "
           "current moment")
    print "..."
    print "..."
    print "..."
    print ("After a couple of months a problem arises, you are inflamed, "
           "what could this be?")
    hepatitis = raw_input ("> ")

    if hepatitis == "hepatitis":
        return 'fifth_thing'

    else:
        return "fourth_thing"

def fifth_thing():
    print "OH NO! Hepatitis!"
    print "What could have caused this?"
    idunno_somthing = raw_input ("> ")

    if idunno_somthing in ("infection", "an infection"):
        print "neat, thats no good."
        print "thank you for coming"
        exit (0)

    elif idunno_somthing in ("sex", "drugs", "rock n roll"):
        print "very funny, what specificly caused it?"
        return "fifth_thing"

    else:
        return "fifth_thing"

ROOMS = {
    'first_thing': first_thing,
    'second_thing': second_thing,
    'third_thing': third_thing,
    'fourth_thing': fourth_thing,
    'fifth_thing': fifth_thing
}

def runner(rooms, start):
    nextRoom = start
    while True:
        room = rooms[nextRoom]
        print "--------"
        nextRoom = room()

runner(ROOMS, 'first_thing')