本文实例为大家分享了python点球小游戏的具体代码,供大家参考,具体内容如下
1.游戏要求:
设置球的方向:左中右三个方向,射门或者扑救动作,循环5次,直接输入方向。电脑随机挑选方向,如果方向相同,那么电脑得分,如果方向相反,那么人得分。
2.分析如何写程序:
1)循环,使用for ..in range()
2) if ..else
3)from random import choice 随机选择
3.脚本如下:
from random import choice
score_person=0
score_com=0
location=['left','center','right']
for i in range (5):
print ("----Round %d You kicked----"%(i+1))
com_choice=choice(location)
print ("Computer's choice is %s"%com_choice)
print ("input what your choice:left/center/right")
you_choice=input()
print ("You have choose:"+you_choice)
if you_choice!=com_choice: # 方向不同,球进!
score_person&#