python入门第二天

变量的输入和输出

Print

可以输出多个参数

Print(‘hello world’,end=’’)

def print(self, *args, sep=' ', end='\n', file=None):

python入门第二天

python入门第二天

 

input

python入门第二天

 

 

类型转换

python入门第二天

 

python入门第二天

 

import random

# 输入猜拳

player = int(input('请输入:剪刀(0) 石头(1) 布(2):'))
# 随机产生0-2之间的整数
computer = random.randint(0, 2)

print('computer:%d' % computer)
# 判断玩家胜负
if((player == 0) and (computer == 2)) or ((player == 1) and (computer == 0)) or ((player == 2) and (computer == 1)):
   
print('你赢了')
elif player == computer:
   
print('平局')
else:
   
print('你输了')

 

 

 

分支语句

If

python入门第二天

python入门第二天

多条件之间的关系

python入门第二天

python入门第二天

 

两种一样

python入门第二天

 

python入门第二天

注意类型准换

Pass指什么都不做,有点像continue

 

 

猜拳游戏

import random

# 输入猜拳

player = int(input('请输入:剪刀(0) 石头(1) 布(2):'))
# 随机产生0-2之间的整数
computer = random.randint(0, 2)

print('computer:%d' % computer)
# 判断玩家胜负
if((player == 0) and (computer == 2)) or ((player == 1) and (computer == 0)) or ((player == 2) and (computer == 1)):
    print('你赢了')
elif player == computer:
    print('平局')
else:
    print('你输了')