学习目标:
python爬虫基础
学习内容:
例题1猜拳小游戏
学习产出:
import random
while 1:
computer_number = random.randint(0, 2)
user_number = int(input('please input 0(石头) or 1(剪刀) or 2(布):'))
if computer_number == user_number:
print('%d VS %d,平局' % (computer_number, user_number))
elif computer_number == 0:
if user_number == 1:
print("%d VS %d, 电脑win!" % (computer_number, user_number))
else:
print('%d VS %d you win!' % (computer_number, user_number))
elif computer_number == 1:
if user_number == 2:
print("%d VS %d, 电脑win!" % (computer_number, user_number))
else:
print('%d VS %d,you win' % (computer_number, user_number))
elif computer_number == 2:
if user_number == 0:
print("%d VS %d, 电脑win!" % (computer_number, user_number))
else:
print('%d VS %d, you win' % (computer_number, user_number))