python 手记10 『笨方法学python 习题31』

如有意见或其他问题可在下方写下评论或加QQ:1693121186
欢迎一起讨论技术问题!

print "You enter a dark room with two doors. Do you go through door #1 or door #2?"

door = raw_input("> ")

if door == "1":
    print "There's a giant bear here eating a cheese cake. What do you do?"
    print "1. Take the cake."
    print "2. Scream at the bear."

    bear = raw_input("> ")

    if bear== "1":
        print "The bear eats your face off. Good job!"
    elif bear == "2":
        print "The bear eats your legs oof. Good job!"
    else:
        print "Well, doing %s is probably better. Bear runs away." % bear

elif door == "2":
    print "You stare into the endless abyss at Cthulhu's retina."
    print "1. Blurberries."
    print "2. Yellow jacket clothespins."
    print "3. Understanding revolvers yelling melodies."

    insanity = raw_input("> ")

    if insanity == "1" or insanity == "2":
        print "Your body survives powered by a mind of jello. Good job!"
    else:
        print "The insanity rots your eyes into a pool of muck. Good job!"

else:
    print "You stumble around and fall on a knife and die. Good job!"

附加练习

为游戏(因为这就是个小游戏)添加新的部分,改变玩家做决定的位置。尽自己的能力扩展这个游戏,不过别把游戏弄得太怪异了
注:我想弄得很多来着,但因为时间有限,所以加了很少一点一点。

# -*- coding: utf-8 -*-
print "You enter a dark room with two doors. Do you go through door #1 or door #2?"

door = raw_input("> ")

if door == "1":
    print "There's a giant bear here eating a cheese cake. What do you do?"
    print "1. Take the cake."
    print "2. Scream at the bear."

    bear = raw_input("> ")

    if bear== "1":
        print "The bear eats your face off. Good job!"
    elif bear == "2":
        print "The bear eats your legs oof. Good job!"
    else:
        print "Well, doing %s is probably better. Bear runs away." % bear

elif door == "2":
    print "You stare into the endless abyss at Cthulhu's retina."
    print "1. Blurberries."
    print "2. Yellow jacket clothespins."
    print "3. Understanding revolvers yelling melodies."

    insanity = raw_input("> ")

    if insanity == "1" or insanity == "2":
        print "Your body survives powered by a mind of jello. Good job!"
    else:
        print "The insanity rots your eyes into a pool of muck. Good job!"

else:
    print "You stumble around and fall on a knife and die. Good job!"

#添加的游戏部分
print "Now you're going to have more difficult questions!"
print "So,You have to type 1 or 2 to determine the next direction~~~"
print "1. To be brave (with a lot of damage and defense)"
print "2. Become a ranger (with the strongest damage and fastest speed"
x1 = raw_input("> ")

if x1 == "1":
    print "So you chose the warrior, and now you're going to go!"
    print "1. Choose to go to the city"
    print "2. Choose to go to city of degara "

    x2 = raw_input("> ")

    if x2 == "1":
        print "Well, go to arajatai"
    elif x2 == "2":
        print "Well, go to the city of digara!"
    else:
        print "Just stay here."

if x1 == "2":
    print "It's a tough job for a ranger, go for it!"

print "-----------------------------------------"
print "\n\t\aThis game is over"
print "-----------------------------------------"

print "\a\t\n----Producer: wang zhenxin!!!----"
print "------------------------------Bye-bye!"


其实这个习题就是让你做一下ifelseelif的练习!
切记:本文谨作提示,切勿复制代码!

猜你喜欢

转载自blog.csdn.net/hys_ntxif/article/details/78638435