gpt4 book ai didi

Python 不运行代码

转载 作者:太空宇宙 更新时间:2023-11-04 01:33:57 25 4
gpt4 key购买 nike

<分区>

我写了一个 python 脚本,它突然停止工作。我不确定为什么会得到任何帮助。控制台只是不显示任何内容。我调用函数从底部开始但没有运气。

import random

year = 1
our_score = 0
their_score = 0
games_played = 0

#opponent's strategy:
def op_strategy():
for i in range (0,1):
rand = random.randint(0,1)
if rand == 0:
return "war"
if rand == 1:
return "peace"


def start():
global our_score, their_score, year
print "====="
print "Year " + str(year)
print "Our Score: " + str(our_score)
print "Their Score: " + str(their_score)
print ""
strategy = raw_input("What is your strategy this year? ")
inputs(strategy)

def inputs(strategy):
our_score = 0
global our_score, their_score, year
if str(strategy) == "peace" or str(strategy) == "war":
print "You chose: " + str(strategy)
op_strat = str(op_strategy())
print "They chose: " + op_strat
if str(strategy) == "war" and str(op_strat) == "war":
print ">>> Everyoner to arms!"
our_score = our_score + 1
their_score = their_score + 1
year = year + 1
elif str(strategy) == "peace" and str(op_strat) == "peace":
print ">>> Peace for everyone!"
our_score = our_score + 3
their_score = their_score + 3
year = year + 1
elif str(strategy) == "peace" and str(op_strat) == "war":
print ">>> They crushed us!"
our_score = our_score
their_score = their_score + 5
year = year + 1
elif str(strategy) == "war" and str(op_strat) == "peace":
print ">>> We crushed them!"
our_score = our_score + 5
their_score = their_score
year = year + 1
if str(year) == "11":
print "====="
print "Final"
print str(our_score)
print str(their_score)
if our_score > their_score:
print ">>>>> We win! <<<<<"
if their_score > our_score:
print ">>>>> They win! <<<<<"
if their_score == our_score:
print ">>>>> It's a tie! <<<<<"
play = raw_input("Play again?")
if play == "y":
start()
if play == "n":
pass
else:
play = raw_input('Invalid response. Please enter "y" or "n".')
if str(strategy) != "peace" and str(strategy) != "war":
strategy = raw_input('Invalid strategy. Enter "peace" or "war": ')
inputs(strategy)
start()
start()

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com