-2

次のようなことをしたい場合、関数を再度呼び出さずに、else ブロックの Is_Programmer() から戻り値を取得するにはどうすればよいですか?

def Is_Programmer():
    if name.lower() == "gregg":
        input = raw_input("What is the point of this app?: ")
        My_Point = Pointless(input)
        return input
    else:
        return False
if Is_Programmer() == False:
    print "I am not going to ask you what the point of this app is, because you didn't write it"
else:
    answer = Return value from Is_Programmer()

提案された解決策を含む完全な「プログラム」

#!/usr/bin/python
# Practicing Python with random programming.

name = raw_input("What are you called?:")

class Pointless(object):
    def __init__(self,point):
        self.point = point
        print "The point of this app, according to %s is ...%s" % (name, "\n" + self.point)

def Is_Programmer():
    if name.lower() == "gregg":        
        input = raw_input("What is the point of this app?: ")        
        My_Point = Pointless(input)
        return input
    else:
        return False
IP=Is_Programmer()
if IP == False:
    print "I am not going to ask you what the point of this app is, because you didn't write it"
else:
    answer = IP
s = name + " thinks the point of this app is\n" + answer + "\n"
f = open('Pointless.txt', 'w')
f.write(s)
f.close
4

2 に答える 2