这是以前刚刚开始学习python时自己编的第一个小游戏,很简单,分享给大家:
import random
胜=0
负=0
平=0
while True:
对方=str(random.randint(1,3))
我方=input('请选择你的出拳:剪刀:1石头:2布:3\n输入“退出”结束\n')
if 我方=='退出':
print ('战绩:')
print (f'胜:{胜}')
print (f'负:{负}')
print (f'平:{平}')
if 胜>负 and 胜>=平:
print ('您是我的英雄!财富!权力!美人!统统送给您!')
elif 负>胜 and 负>=平:
print ('莫以成败论英雄,谁说站在光里的才算英雄?')
else:
print ('大隐隐于市,平平凡凡才是真!')
print ('鼓得白!塞油捺哪!')
break
else:
if 我方=='1' and 对方=='1':
print ('平局!小样儿,再来啦!\n')
平=平+1
elif 我方=='1' and 对方=='2':
print ('你输啦!菜就菜了呗!\n')
负=负+1
elif 我方=='1' and 对方=='3':
print ('你赢啦!爱你哟!\n')
胜=胜+1
elif 我方=='2' and 对方=='1':
print ('你赢啦!爱你哟!\n')
胜=胜+1
elif 我方=='2' and 对方=='2':
print ('平局!小样儿,再来啦!\n')
平=平+1
elif 我方=='2' and 对方=='3':
print ('你输啦!菜就菜了呗!\n')
负=负+1
elif 我方=='3' and 对方=='1':
print ('你输啦!菜就菜了呗!\n')
负=负+1
elif 我方=='3' and 对方=='2':
print ('你赢啦!爱你哟!\n')
胜=胜+1
elif 我方=='3' and 对方=='3':
print ('平局!小样儿,再来啦!\n')
平=平+1
else:
print ('没按套路出牌,哥们。\n')