|
本帖最后由 mylife18 于 2017-9-28 12:10 编辑
# -*- coding: utf-8 -*-
from sys import exit
first_sentence_property = "[1]" # 此处 first_sentence_property = "[1]"
second_sentence_mood = "[2]"
first_sentence = "We don't read and write poetry because it's %s" % first_sentence_property + "."
second_sentence = "We read and write poetry because we are members of human being race. And human race is filled with %s" % second_sentence_mood + "."
print "Now let us make some choice for these sentences.\n>>>", first_sentence + "\n", second_sentence
def first_choice():
global first_sentence_property # 声明 global first_sentence_property
print first_sentence_property # 此处已验证了 first_sentence_property = "[1]"
global first_sentence
while True:
property = raw_input('>[1]-[boring, cute, confused]\n>')
if property == "boring" :
print property
first_sentence_property = property # 此处将 first_sentence_property 赋值为 "boring"
print first_sentence_property # 此处已验证了 first_sentence_property = "boring"
print "\n***\nHere is your anwser:", first_sentence # 为何 first_sentence_property 不是 "boring"
end_choice()
elif property == "cute":
second_choice()
elif property == "confused":
end_choice()
else:
print """
Your choice is out of range.
Please choose it in "boring, cute, confused"
"""
return property
def second_choice():
print "Good! let us explore another one."
print """
We read and write poetry because
we are members of human being race.
And human race is filled with [2]
"""
while True:
mood = raw_input('>[2]-[lazy, passion, angry]\n>')
if mood == "lazy":
end_choice()
elif mood == "passion":
print """
Good job! This gift is for you:
>>>>>>
Medicine, law, business, engineering:
these are noble pursuits and necessary to
sustain life. But the poetry...beauty, romance, love...
these are what we stay alive for.
"""
exit()
elif mood == "angry":
end_choice()
else:
print """
!!!Your choice is out of range.
Please choose it in 'lazy, passion, angry'
"""
def summarize_sentences():
global first_sentence_property
first_sentence_property = first_choice()
print "***\nHere is your anwser:"
return first_sentence
def restart():
print "\nDo you want to play again? 'y' or 'no' "
while True:
play_again = raw_input('>')
if play_again == "y":
first_choice()
elif play_again == "n":
exit()
else:
print "!!!I don't understand!"
def end_choice():
print "ah...I think it can be better.\n***"
# summarize_sentences()
restart()
first_choice()
版本信息:Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
系统为:win7 64bit
开始变量 first_sentence_property 赋值为「 [1] 」
在函数 first_choice 中,我已把 first_sentence_property 声明 global,并重新赋值为「boring」了,且已验证其确实为「boring」
为何在输出 first_sentence 时,其中的 first_sentence_property 仍然为「 [1] 」,而不是「boring」,新手一枚望指导!
|
|