所以我设计了一个你编写足球(足球)统计数据的程序,然后它会打印你编写它的次数。它一直在工作,但我已经添加了退出功能的选项,这导致我跟随问题。如果你没有写过一次至少一次的统计数据就会崩溃。所以我修复了它,但现在当我尝试运行它时,它开始计数但它也计算为0,它之前没有。这里只有一个统计数据,因为我认为在这里复制粘贴超过1000行代码是不合适的:
pk_range_goal = range(0, 1000)
pk_list_goal = list(pk_range_goal)
pk_input = '''goal/saved/missed
'''
def body():
while True:
choice = input("")
first_number_pk_goal = pk_list_goal[0]
integer_pk_number_goal = int(first_number_pk_goal)
if choice == "pk":
good_bad_input_pk = input(pk_input)
if good_bad_input_pk == "goal":
pk_list_goal.remove(first_number_pk_goal)
integer_pk_number_goal = int(first_number_pk_goal)
string_number_pk_goal = str(first_number_pk_goal)
print("Penalty Kick goal(s): ", string_number_pk_goal)
elif choice == "q":
print("Are you sure that you want to finish the stat counting? (yes/no)")
quit_choice = input()
if quit_choice == "yes":
if integer_pk_number_goal >= 1:
print("Penalty Kick goal(s): ", string_number_pk_goal)
elif integer_pk_number_goal == 0:
print("Penalty Kick goal(s): 0")
else:
pass
break
else:
pass
body()
编辑:我试图让范围从1开始但是你需要写两次以便转到2
完整
# -----> * INTRODUCTION * <-----
Commands = ''' STAT ------------> COMMAND
Penalty Kick -----> pk
-> Goal ----------> goal
-> Saved ---------> saved
-> Missed --------> missed
Free Kick --------> fk
Corner Kick ------> ck
Throw In ---------> ti
Cross ------------> cross
-> Good Delivery -> gd
-> Good Delivery -> pd
1 versus 1 ------> 1v1
-> Won ----------> w
-> Lost ---------> l
Shot ------------> shot
Header ----------> header
-> On Target ----> on target
-> Off Target ---> off target
Save ------------> save
To quit press q
'''
print(Commands)
# -----> * Penalty Kicks Variables * <-----
pk_range = range(0, 1000)
pk_list = list(pk_range)
pk_range_goal = range(0, 1000)
pk_list_goal = list(pk_range_goal)
pk_range_saved = range(0, 1000)
pk_list_saved = list(pk_range_saved)
pk_range_missed = range(0, 1000)
pk_list_missed = list(pk_range_missed)
pk_input = '''goal/saved/missed
'''
# -----> * Free Kicks Variables <-----
fk_range = range(0, 1000)
fk_list = list(fk_range)
fk_range_gd = range(0, 1000)
fk_list_gd = list(fk_range_gd)
fk_range_pd = range(0, 1000)
fk_list_pd = list(fk_range_pd)
fk_input = '''gd/pd
'''
# -----> * Corner Kicks Variables * <-----
ck_range = range(0, 1000)
ck_list = list(ck_range)
ck_range_gd = range(0, 1000)
ck_list_gd = list(ck_range_gd)
ck_range_pd = range(0, 1000)
ck_list_pd = list(ck_range_pd)
ck_input = '''gd/pd
'''
# -----> * Throw Ins Variables * <-----
ti_range = range(0, 1000)
ti_list = list(ti_range)
ti_range_gd = range(0, 1000)
ti_list_gd = list(ti_range_gd)
ti_range_pd = range(0, 1000)
ti_list_pd = list(ti_range_pd)
ti_input = '''gd/pd
'''
# -----> * Crosses Variables * <-----
crosses_range = range(0, 1000)
crosses_list = list(crosses_range)
crosses_range_gd = range(0, 1000)
crosses_list_gd = list(crosses_range_gd)
crosses_range_pd = range(0, 1000)
crosses_list_pd = list(crosses_range_pd)
crosses_input = '''gd/pd
'''
# -----> * 0 vs 0 Variables * <-----
v1_range = range(0, 1000)
v1_list = list(v1_range)
v1_range_w = range(0, 1000)
v1_list_w = list(v1_range_w)
v1_range_l = range(0, 1000)
v1_list_l = list(v1_range_l)
v1_input = '''w/l
'''
# -----> * Shots Variables * <-----
shots_range = range(0, 1000)
shots_list = list(shots_range)
shots_range_gd = range(0, 1000)
shots_list_gd = list(shots_range_gd)
shots_range_pd = range(0, 1000)
shots_list_pd = list(shots_range_pd)
shots_input = '''on target/off target
'''
# -----> * Headers Variables * <-----
headers_range = range(0, 1000)
headers_list = list(headers_range)
headers_range_gd = range(0, 1000)
headers_list_gd = list(headers_range_gd)
headers_range_pd = range(0, 1000)
headers_list_pd = list(headers_range_pd)
headers_input = '''on target/off target
'''
# -----> * Saves Variables * <-----
saves_range = range(1, 1000)
saves_list = list(saves_range)
# -----> * Long Pass Variables * <-----
long_passes_range = range(1, 1000)
long_passes_list = list(long_passes_range)
long_passes_range_first_touch = range(1, 1000)
long_passes_list_first_touch = list(long_passes_range_first_touch)
long_passes_range_second_touch = range(1, 1000)
long_passes_list_second_touch = list(long_passes_range_second_touch)
long_passes_input = '''first touch/second touch
'''
# -----> * Main Function * <-----
def body():
while True:
choice = input("")
# -----> * Penalty Kicks Goal Variables * <-----
# -----> * Penalty Kicks Missed Variables * <-----
first_number_pk_missed = pk_list_missed[0]
integer_pk_number_missed = int(first_number_pk_missed)
number_pk_missed = integer_pk_number_missed - 1
string_number_pk_missed = str(number_pk_missed)
# -----> * Penalty Kicks Saved Variables * <-----
first_number_pk_saved = pk_list_saved[0]
integer_pk_number_saved = int(first_number_pk_saved)
number_pk_saved = integer_pk_number_saved - 1
string_number_pk_saved = str(number_pk_saved)
# -----> * Total Penalty Kicks Variables * <-----
first_number_pk = pk_list[0]
integer_pk_number = int(first_number_pk)
number_pk = integer_pk_number - 1
string_number_pk = str(number_pk)
# -----> * Penalty Kicks Function * <-----
first_number_pk_goal = pk_list_goal[0]
integer_pk_number_goal = int(first_number_pk_goal)
if choice == "pk":
good_bad_input_pk = input(pk_input)
if good_bad_input_pk == "goal":
integer_pk_number_goal = 0
string_number_pk_goal = str(first_number_pk_goal)
pk_list_goal.remove(first_number_pk_goal)
print("Penalty Kick goal(s): ", string_number_pk_goal)
elif good_bad_input_pk == "saved":
print("Penalty Kick(s) saved: ", string_number_pk_saved)
elif good_bad_input_pk == "missed":
print("Penalty Kick(s) missed: ", string_number_pk_missed)
else:
pass
print("Penalty Kick(s) : ", string_number_pk)
# -----> * Free Kicks with Good Delivery Variables * <-----
first_number_fk_gd = fk_list_gd[0]
integer_fk_number_gd = int(first_number_fk_gd)
number_fk_gd = integer_fk_number_gd - 1
string_number_fk_gd = str(number_fk_gd)
# -----> * Free Kicks with Poor Delivery Variables * <-----
first_number_fk_pd = fk_list_pd[0]
integer_fk_number_pd = int(first_number_fk_pd)
number_fk_pd = integer_fk_number_pd - 1
string_number_fk_pd = str(number_fk_pd)
# -----> * Free Kicks Variables * <-----
first_number_pk = pk_list[0]
integer_pk_number = int(first_number_pk)
number_pk = integer_pk_number - 1
string_number_pk = str(number_pk)
# -----> * Free Kicks Function * <-----
if choice == "fk":
good_bad_input_fk = input(fk_input)
if good_bad_input_fk == "gd":
print("Free Kick(s) with a Good Delivery: ", string_number_fk_gd)
elif good_bad_input_fk == "pd":
print("Free Kick(s) with a Poor Delivery: ", string_number_fk_pd)
else:
pass
print("Free Kick(s)", string_number_fk)
# -----> * Corner Kick Variables * <-----
elif choice == "ck":
good_bad_input_ck = input(ck_input)
if good_bad_input_ck == "gd":
first_number_ck_gd = ck_list_gd[0]
ck_list_gd.remove(first_number_ck_gd)
number_ck_gd = ck_list_gd[0]
string_number_ck_gd = str(number_ck_gd)
print("Corner Kick(s) with a Good Delivery: ", string_number_ck_gd)
elif good_bad_input_ck == "pd":
first_number_ck_pd = ck_list_pd[0]
ck_list_pd.remove(first_number_ck_pd)
number_ck_pd = ck_list_pd[0]
string_number_ck_pd = str(number_ck_pd)
print("Corner Kick(s) with a Poor Delivery: ", string_number_ck_pd)
else:
pass
first_number_ck = ck_list[0]
ck_list.remove(first_number_ck)
number_ck = ck_list[0]
string_number_ck = str(number_ck)
print("Corner Kick(s): ", string_number_ck)
# -----> * Throw Ins Functions * <-----
elif choice == "ti":
good_bad_input_ti = input(ti_input)
if good_bad_input_ti == "gd":
first_number_ti_gd = ti_list_gd[0]
ti_list_gd.remove(first_number_ti_gd)
number_ti_gd = ti_list_gd[0]
string_number_ti_gd = str(number_ti_gd)
print("Throw In(s) with a Good Delivery: ", string_number_ti_gd)
elif good_bad_input_ti == "pd":
first_number_ti_pd = ti_list_pd[0]
ti_list_pd.remove(first_number_ti_pd)
number_ti_pd = ti_list_pd[0]
string_number_ti_pd = str(number_ti_pd)
print("Throw In(s) with a Poor Delivery: ", string_number_ti_pd)
else:
pass
first_number_ti = ti_list[0]
ti_list.remove(first_number_ti)
number_ti = ti_list[0]
string_number_ti = str(number_ti)
print("Throw In(s): ", string_number_ti)
# -----> * Crosses Function * <-----
elif choice == "cross":
good_bad_input_crosses = input(crosses_input)
if good_bad_input_crosses == "gd":
first_number_crosses_gd = crosses_list_gd[0]
crosses_list_gd.remove(first_number_crosses_gd)
number_crosses_gd = crosses_list_gd[0]
string_number_crosses_gd = str(number_crosses_gd)
print("Cross(es) with a Good Delivery: ", string_number_crosses_gd)
elif good_bad_input_crosses == "pd":
first_number_crosses_pd = crosses_list_pd[0]
crosses_list_pd.remove(first_number_crosses_pd)
number_crosses_pd = crosses_list_pd[0]
string_number_crosses_pd = str(number_crosses_pd)
print("Cross(es) with a Good Delivery: ", string_number_crosses_pd)
else:
pass
first_number_crosses = crosses_list[0]
crosses_list.remove(first_number_crosses)
number_crosses = crosses_list[0]
string_number_crosses = str(number_crosses)
print("Cross(es): ", string_number_crosses)
# -----> * 1 versus 1 Function * <-----
elif choice == "1v1":
good_bad_input_v1 = input(v1_input)
if good_bad_input_v1 == "w":
first_number_v1_w = v1_list_w[0]
v1_list_w.remove(first_number_v1_w)
number_v1_w = v1_list_w[0]
string_number_v1_w = str(number_v1_w)
print("Won 1vs1: ", string_number_v1_w)
elif good_bad_input_v1 == "l":
first_number_v1_l = v1_list_l[0]
v1_list_l.remove(first_number_v1_l)
number_v1_l = v1_list_l[0]
string_number_v1_l = str(number_v1_l)
print("Lost 1vs1: ", string_number_v1_l)
else:
pass
first_number_v1 = v1_list[0]
v1_list.remove(first_number_v1)
number_v1 = v1_list[0]
string_number_v1 = str(number_v1)
print("1vs1: ", string_number_v1)
# -----> * Shots Function * <-----
elif choice == "shot":
good_bad_input_shots = input(shots_input)
if good_bad_input_shots == "on target":
first_number_shots_gd = shots_list_gd[0]
shots_list_gd.remove(first_number_shots_gd)
number_shots_gd = shots_list_gd[0]
string_number_shots_gd = str(number_shots_gd)
print("Shot(s) on target: ", string_number_shots_gd)
elif good_bad_input_shots == "off target":
first_number_shots_pd = shots_list_pd[0]
shots_list_pd.remove(first_number_shots_pd)
number_shots_pd = shots_list_pd[0]
string_number_shots_pd = str(number_shots_pd)
print("Shot(s) off target: ", string_number_shots_pd)
else:
pass
first_number_shots = shots_list[0]
shots_list.remove(first_number_shots)
number_shots = shots_list[0]
string_number_shots = str(number_shots)
print("Shot(s): ", string_number_shots)
# -----> * Headers Function * <-----
elif choice == "header":
good_bad_input_headers = input(headers_input)
if good_bad_input_headers == "on target":
first_number_headers_gd = headers_list_gd[0]
headers_list_gd.remove(first_number_headers_gd)
number_headers_gd = headers_list_gd[0]
string_number_headers_gd = str(number_headers_gd)
print("Header(s) on target: ", string_number_headers_gd)
elif good_bad_input_headers == "off target":
first_number_headers_pd = headers_list_pd[0]
headers_list_pd.remove(first_number_headers_pd)
number_headers_pd = headers_list_pd[0]
string_number_headers_pd = str(number_headers_pd)
print("Header(s) off target: ", string_number_headers_pd)
else:
pass
first_number_headers = headers_list[0]
headers_list.remove(first_number_headers)
number_headers = headers_list[0]
string_number_headers = str(number_headers)
print("Header(s): ", string_number_headers)
# -----> * Long Passes * <-----
elif choice == "long pass":
good_bad_input_long_passes = input(long_passes_input)
first_number_long_passes = long_passes_list[0]
long_passes_list.remove(first_number_long_passes)
number_long_passes = long_passes_list[0]
string_number_long_passes = str(number_long_passes)
print("Long Pass(es): ", string_number_long_passes)
if good_bad_input_long_passes == "first touch":
first_number_long_passes_first_touch = long_passes_list_first_touch[0]
long_passes_list_first_touch.remove(first_number_long_passes_first_touch)
number_long_passes_first_touch = long_passes_list_first_touch[0]
string_number_long_passes_first_touch = str(number_long_passes_first_touch)
print("Long Pass(es) first touch: ", string_number_long_passes_first_touch)
elif good_bad_input_long_passes == "second touch":
first_number_long_passes_second_touch = long_passes_list_second_touch[0]
long_passes_list_second_touch.remove(first_number_long_passes_second_touch)
number_long_passes_second_touch = long_passes_list_second_touch[0]
string_number_long_passes_second_touch = str(number_long_passes_second_touch)
print("Long Pass(es) second touch: ", string_number_long_passes_second_touch)
else:
pass
# -----> * Saves * <-----
elif choice == "save":
first_number_save = saves_list[0]
saves_list.remove(first_number_save)
number_save = saves_list[0]
string_number_save = str(number_save)
print("Save(s)", string_number_save)
elif choice == "q":
print("Are you sure that you want to finish the stat counting? (yes/no)")
quit_choice = input()
if quit_choice == "yes":
# -----> * Penalty_Kicks_goal_Quit_Function * <-----
if integer_pk_number_goal >= 1:
print("Penalty Kick goal(s): ", string_number_pk_goal)
elif integer_pk_number_goal == 0:
print("Penalty Kick goal(s): 0")
# -----> * Penalty_Kicks_saved_Quit_Function * <-----
if integer_pk_number_saved >= 1:
print("Saved Penalty Kick(s): ", string_number_pk_saved)
elif integer_pk_number_saved == 0:
print("Saved Penalty Kick(s): 0")
# -----> * Penalty_Kicks_missed_Quit_Function * <-----
if integer_pk_number_missed >= 1:
print("Missed Penalty Kick(s): ", string_number_pk_missed)
elif integer_pk_number_missed == 0:
print("Missed Penalty Kick(s): 0")
# -----> * Penalty_Kicks_Quit_Function * <-----
if integer_pk_number >= 1:
print("Penalty Kick(s): ", string_number_pk)
elif integer_pk_number == 0:
print("Penalty Kick(s): 0")
else:
pass
# -----> * Free_Kicks_gd_Quit_Function * <-----
if integer_fk_number_gd >= 1:
print("Free Kick(s) with Good delivery: ", string_number_fk_gd)
elif integer_fk_number_gd == 0:
print("Free Kick(s) with Good delivery: 0")
# -----> * Free_Kicks_Quit_Function * <-----
if integer_fk_number_pd >= 1:
print("Free Kick(s) with Poor delivery: ", string_number_fk_pd)
elif integer_fk_number_pd == 0:
print("Free Kick(s) with Poor delivery: 0")
# -----> * Free_Kicks_Quit_Function * <-----
if integer_fk_number >= 1:
print("Free Kick(s): ", string_number_fk)
elif integer_fk_number == 0:
print("Free Kick(s): 0")
break
elif quit_choice == "no":
pass
else:
pass
body()
在完整的源代码中,我没有在所有统计数据中添加退出功能,因为我在最小化时没有,因为它不起作用,这将是浪费时间。此外,您可能会发现其他错误。
答案 0 :(得分:0)
尝试在变量被调用之前将其定义为False然后为true