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))
發佈了12 篇原創文章 · 獲贊 7 · 訪問量 1540
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章