python簡單小遊戲代碼
2023-08-03 02:09:26 1
1、Python猜拳小遊戲代碼:
2、import random #導入隨機模塊
3、
4、num = 1
5、yin_num = 0
6、shu_num = 0
7、while num 2:
12、 print('不能出大於2的值')
13、 else:
14、 data = ['石頭', '剪刀', '布']
15、 com = random.randint(0, 2)
16、 print(您出的是{},電腦出的是{}.format(data[user], data[com]))
17、 if user == com:
18、 print('平局')
19、 continue
20、 elif (user == 0 and com == 1) or (user == 1 and com == 2) or (user == 2 and com == 0):
21、 print('你贏了')
22、 yin_num += 1
23、 else:
24、 print('你輸了')
25、 shu_num += 1
26、 num += 1
27、Python數字炸彈小遊戲代碼:
28、import random
29、import time
30、
31、bomb = random.randint(1, 99)
32、print(bomb)
33、start = 0
34、end = 99
35、while 1 == 1:
36、
37、 people = int(input('請輸入{}到{}之間的數:'.format(start, end)))
38、 if people > bomb:
39、 print('大了')
40、 end = people
41、 elif people bomb:
52、 print('大了')
53、 end = com
54、 elif com < bomb:
55、 print('小了')
56、 start = com
57、 else:
58、 print('BOOM!!!')
59、 break
關鍵詞: python 簡單 遊戲 代碼