点球小游戏python脚本

人只需不取得标的目标,就不会取得自己。有没有人爱,我们也要努力做一个可爱的人。不埋怨谁,不嘲笑谁,也不羡慕谁,阳光下灿烂,风雨中奔跑,做自己的梦,走自己的路。

本文实例为大家分享了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+=1  #人得分
    print ("Kicked!")
  else:
    print ("Saved unsuccesfully!") #补救

  print ("Score:%d(person)-%d(com)\n" %(score_person, score_com))
  print ("----Round %d You saved----"%(i+1))
  com_choice=choice(location)
  print ("Computer's choice is %s"%com_choice)
  print ("input what your choice is:left/center/right")
  if you_choice==com_choice: #方向相同,球不进!
    print ("Saved unsucessfully!")
    score_com+=1  #电脑得分
  else:
    print ("Kicked")
  print ("Score:%d(person)-%d(com)\n"%(score_person, score_com))

这小游戏的功能类似于猜数游戏。

到此这篇关于点球小游戏python脚本就介绍到这了。生活就像海洋,只有意志坚强的人,才能到达彼岸。更多相关点球小游戏python脚本内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
Python自动化运维-使用Python脚本监控华为AR路由器关键路由变化

Python自动化运维-netmiko模块设备自动发现

Python自动化运维—netmiko模块连接并配置华为交换机

Python自动化运维-利用Python-netmiko模块备份设备配置

Python自动化运维-Paramiko模块和堡垒机实战