猜拳,随机n位密码.

1.猜拳:
import random
list = ['石头','剪刀','布']
y = input('''
(0) 石头
(1) 剪刀
(2) 布
请出拳(0/1/2):
*******************''')
computer = random.choice(list)
you = list[int(y)]
win_list = [['石头','剪刀'],['剪刀','布'],['布','石头']]
if [you,computer] in win_list:
print('你出拳:%s,电脑出拳:%s,你赢了!' % (you,computer))
elif you == computer:
print('平局!!!')
else:
print('你出拳:%s,电脑出拳:%s,你输了!' % (you,computer))

2.随机n位密码
import random
import string
result = ''
i = 1
n = int(input('随机生成几位密码:'))
char = string.ascii_letters + string.digits + '_'
while i<=n:
a = random.choice(char)
result += a
i += 1
print(result)
posted @ 2019-03-27 21:27  编程小白ZJX  阅读(151)  评论(0编辑  收藏  举报