Falcon Lee (小草)
嗨各位,我是小草~ 這裡是廢炸的簡報天地
用 Python 打造你的遊戲
2020
小草、RexWu
print("Hello, World!")
name = input("請告訴我你的名字:")
if(age < 16):
print("警察伯伯,就是這個人!")
elif(age < 18):
print("警察伯伯,還是這個人!")
else:
print("你合法了")
x = 30
y = 25
print(x + y) #加法
print(x - y) #減法
print(x * y) #乘法
print(x / y) #除法
print(x % y) #餘數除法
print(x ** y)#次方
import time #導入時間的功能
times = input('請輸入等待時間:')
time.sleep(times)
print('等待了 ' + times + ' 秒')
型態 | 簡介 | 範例 |
---|---|---|
str | 字串 | "Hello!" |
int | 整數 | 5 |
float | 小數 aka 浮點數 | 51.1 |
bool | 布林(True / False) | True |
complex | 複數 | 1 + 5j |
# 創建陣列
score = [81, 99, 49, 15, 60, 33, 66, 82]
# 可以放不同的型態在同個陣列裡,但是不建議
person = ["小草", 20, 179.9]
# 創建空陣列
score = []
score = list()
print(score[0])
print(score[1])
print(score[2])
print(score[3])
print(score[4])
print(score[5])
print(score[6])
print(score[7])
print(score[8])
print(score[9])
print(score[10])
print(score[11])
print(score[12])
print(score[13])
print(score[14])
print(score[15])
print(score[16])
print(score[17])
print(score[18])
print(score[19])
print(score[20])
print(score[21])
print(score[22])
print(score[23])
print(score[24])
print(score[25])
print(score[26])
print(score[27])
print(score[28])
print(score[29])
print(score[30])
print(score[31])
print(score[32])
print(score[33])
print(score[34])
print(score[35])
print(score[36])
print(score[37])
print(score[38])
print(score[39])
print(score[40])
print(score[41])
print(score[42])
print(score[43])
print(score[44])
print(score[45])
print(score[46])
print(score[47])
print(score[48])
print(score[49])
print(score[50])
print(score[51])
print(score[52])
print(score[53])
print(score[54])
print(score[55])
print(score[56])
print(score[57])
print(score[58])
print(score[59])
print(score[60])
print(score[61])
print(score[62])
print(score[63])
print(score[64])
print(score[65])
print(score[66])
print(score[67])
print(score[68])
print(score[69])
print(score[70])
print(score[71])
print(score[72])
print(score[73])
print(score[74])
print(score[75])
print(score[76])
print(score[77])
print(score[78])
print(score[79])
print(score[80])
print(score[81])
print(score[82])
print(score[83])
print(score[84])
print(score[85])
print(score[86])
print(score[87])
print(score[88])
print(score[89])
print(score[90])
print(score[91])
print(score[92])
print(score[93])
print(score[94])
print(score[95])
print(score[96])
print(score[97])
print(score[98])
print(score[99])
nums = list()
for i in range(0, 5):
x = input("請輸入第" + str(i) + "個數字: ")
nums.append(x)
# 執行 10 次
i = 0
while i < 10:
print(i)
i += 1
import random
# 隨機產生一個 0 ~ 100 的整數
random.randint(0, 100)
# 隨機產生一個 0 ~ 1 的浮點數
random.random()
# 隨機產生一個 0 ~ 10 的浮點數
random.uniform(0, 10)
{"name": "Rex", "age": 19, "student?": True}
"name": "Rex"
key
value
函數
print()
dict()
list()
input()
.time()
set()
tuple()
len()
.pop()
.push()
.push()
def setName(name):
if(name != None):
return name
else:
print("ERROR! 名字不能為空白!")
return ""
print(setName())
print(setName("小草"))
class Player:
def __init__(self, hp, atk, def_, inventory):
self.hp = hp
self.atk = atk
self.def_ = def_
self.inventory = inventory
def attack(self, target):
target.hp = target.def_ - self.atk
def add():
try:
x = int(input('請輸入 x :'))
y = int(input('請輸入 y :'))
print(x + y)
except:
print('輸入錯誤 請輸入整數')
add()
add()
f = open("檔案名稱", "模式")
file = open("檔案名稱", "r")
file = open("檔案名稱", "r")
data = file.read()
data = open("檔案名稱", "r").read()
file = open("檔案名稱", "w")
file.write(data)
open("檔案名稱", "w").write(data)
file.close()
open("檔案名稱", "w").write(data).close()
data = {"Name": "小草", "age": 20}
fileName = "小草檔案"
f = open(fileName, "wb")
pk.dump(data, f)
fileName = "小草檔案"
f = open(fileName, "rb").read()
data = pk.loads(f)
print(data)
By Falcon Lee (小草)