|
发表于 2017-12-2 01:16:55
|
显示全部楼层
本帖最后由 shigure_takimi 于 2017-12-2 01:17 编辑
- # coding:utf-8
- import random
- option = [1,2,3]
- game_over = False
- while not game_over:
- per = input('请出拳:\n1-->石頭\n2-->剪刀\n3-->布\n按n退出。\n')
-
- if per in ['n','N']:
- print("Quit Game.")
- game_over = True
- elif per.isnumeric() and int(per) in option:
- com = random.randint(1,3)
- print("Computer selected %d" % com)
- if int(per) == com:
- print("Draw Game!")
- elif int(per)==1 and com == 2 or \
- int(per) == 2 and com == 3 or \
- int(per) == 3 and com == 1:
- print("You win!")
- else:
- print("You lost!")
- end_game = input("Press N to end game.\nPress any other Key to Continue.\n")
- if end_game in ['n','N']:
- print("Quit Game.")
- game_over = True
- else:
- print("输入不合法。")
-
- ##
- >>>
- 请出拳:
- 1-->石頭
- 2-->剪刀
- 3-->布
- 按n退出。
- 1
- Computer selected 3
- You lost!
- Press N to end game.
- Press any other Key to Continue.
- 请出拳:
- 1-->石頭
- 2-->剪刀
- 3-->布
- 按n退出。
- 2
- Computer selected 3
- You win!
- Press N to end game.
- Press any other Key to Continue.
- n
- Quit Game.
- >>>
复制代码
之前用pygame还写了个小的猜拳。
http://bbs.fishc.com/thread-85240-1-1.html |
|