在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python 簡單計數(shù)器的實現(xiàn)

python 簡單計數(shù)器的實現(xiàn)

各位大佬好, 我想要寫一個計數(shù)器,每次一個循環(huán)后,計數(shù)器數(shù)量加一,但不知道怎么實現(xiàn)。麻煩各位賜教

def count_turn(turn=0):

if turn == 0:
    turn += 1
elif turn >=1:
    turn += 1
return turn

def add_turn(turn):

turn += 1
return turn

def leave_stay():

print("="*50)
reply = input("Do you want to quit the game or continue playing? "
              "\n'q' for quit, 'c' for continue ")
print("")
return reply

def execute(reply,):

if reply == 'q':
    signal = False
    return  signal
elif reply == 'c':
    main()
else:
    leave_stay()

def main(turn =0):

turn = count_turn(turn)
print("first:", turn)
signal = True
if signal:
    turn = count_turn(turn)
    turn=add_turn(turn)
    print("here is the turn :", turn)
    reply = leave_stay()
    execute(reply)

main()

回答
編輯回答
薔薇花
class Counter(object):
    def __init__(self, start=0):
        self.num = start
    def count(self):
        self.num += 1
        return self.num

調(diào)用如下:

>>> c = Counter()
>>> c.count()
1
>>> c.count()
2
2017年6月8日 08:59
編輯回答
鐧簞噯
def execute(reply,):
    while reply not in 'qc':
        reply = leave_stay()
    return True if reply=='c' else False

def main(turn=0):
    turn = count_turn(turn)
    print("first:", turn)
    signal = True
    while signal:
        turn = count_turn(turn)
        print("here is the turn :", turn)
        reply = leave_stay()
        signal = execute(reply)

main()
2017年5月30日 23:13