Python自学笔记02

Python自学笔记02

#数据类型
数值型:int float
布尔型:bool
空对象:None
列表:list
元组:tuple
字典:dict4
集合:set
字符串:str
list、tuple、set、dict、range()可以把他们划分为序列

type() 检查数据类型
bool() 将给定的参数转换为bool类型
0.0 0 “” ''空字符串 []空列表 False ()空元组 {}空字典 None空对象 都是FALSE

**
'''
实现简单猜拳游戏
'''
import random
player = int(input("please input 0:剪刀  1:石头  2:布"))

PC = random.randint(0,2)

print(player)

print(PC)

if((player==0 and PC==2) or (player==1 and PC==0) or (player==2 and PC==1)):
    print("player win!")
elif(player==PC):
    print("平局")
else:
    print("player lose!")
#简单计算机程序
def caul(Fir,Yun,Sec):
    if(Yun=='-'):
        return Fir-Sec
    elif(Yun=='+'):
        return Fir+Sec
    elif(Yun=='*'):
        return Fir*Sec
    elif(Yun=='/'):
        if(Sec==0):
            print("illgal!")
            return
        else:
            return Fir/Sec


Fir = float(input("please input the first number:"))
Yun = input("进行啥子运算?")
Sec = float(input("please input the second number:"))
print("The result is:%s"%caul(Fir,Yun,Sec))
发布了11 篇原创文章 · 获赞 5 · 访问量 460

猜你喜欢

转载自blog.csdn.net/weixin_43739167/article/details/89965484
今日推荐