python
print('你好')
print('Hello Python')
print('今天')
print('123')
print('Hello Python')
print('Hello', 'World', 'test', 123)
print(9876 + 1)
print('9876' + '1' + 'Hello')
# input函式輸入的資料存放在a變數裡
a = input('請輸入一個數字:')
# input函式輸入的資料存放在b變數裡
b = input('請再輸入一個數字:')
# a字串轉換成數字後會存放在c
c = int(a)
d = int(b)
print(a + b)
print(c + d)
a = True
b = type(a)
print(b)
name = input('請輸入名字:')
age = input('請輸入年齡:')
# 字串格式化
print('你的名字叫', name, ", 年齡為:", age, '歲')
print(f'你的名字叫{name}, 年齡為:{age}歲')
num1 = int(input('請輸入第一個數字'))
num2 = int(input('請輸入第二個數字'))
print(f'{num1}和{num2}的總合為{num1 + num2}')
a = [1, 2, 3, 1, 5] # list
b = [1, 2, 3, 1, 5] # list
c = [1, 2, 3, 1, 5] # list
print(a[4])
print(a[3])
print(a[2])
print(a[1])
print(a[0])
print(a[0]+a[1]+a[2]+a[3]+a[4])
a.append(9) # 將9增加到a list裡面去
a.insert(2, 'xyz')
b.append('abc')
c.append(True)
# del a[0]
# del b[0]
# del c[0]
print(a)
print(b)
print(c)
# t = sum(a)
# print("t=", t)
import random # 亂數模組
import datetime # 日期模組
wday = datetime.date.today().weekday() # 0 = 星期一 ~ 6 = 星期日
print(wday) # 測試用
if wday == 0:
print('今天是星期一')
if wday == 1:
print('今天是星期二')
if wday == 2:
print('今天是星期三')
if wday == 3:
print('今天是星期四')
if wday == 4:
print('今天是星期五')
if wday == 5:
print('今天是星期六')
if wday == 6:
print('今天是星期日')
# 組合
if wday == 0:
print('今天是星期一')
elif wday == 1: # else if
print('今天是星期二')
elif wday == 2:
print('今天是星期三')
elif wday == 3:
print('今天是星期四')
elif wday == 4:
print('今天是星期五')
elif wday == 5:
print('今天是星期六')
elif wday == 6:
print('今天是星期日')
import random
result = random.randint(1, 5) # 抽籤
if result == 1:
print('今天會撿到錢')
elif result == 2:
print('明天加薪')
elif result == 3:
print('今天中彩卷')
elif result == 4:
print('今天摸彩抽到iPhone')
else:
print('今天踩到大便')
a = 4
b = 9
c = 6
# 判斷式一號
if a > b and b > c:
print('ok1')
else:
print('not ok1') # V
# 判斷式二號
if a > b or b > c:
print('ok2') # V
else:
print('not ok2')
# 判斷式三號
if a > b > c: # if a > b and b > c:
print('ok3')
else:
print('not ok3') # V
# 判斷式四號
# 巢狀判斷式
if a > b:
if b > c:
print('ok4')
else:
print('not ok4') # V
user = int(input('請輸入一個數字:'))
print('你輸入的是:', end='')
# if user % 2 == 0:
# print('偶數')
# else:
# print('奇數')
print('偶數' if user % 2 == 0 else '奇數')
import csv
with open('Fstdata.csv', 'r', encoding='utf-8') as my_file:
for line in my_file:
col = line.split(',')
if '人生' in col[1]:
print(col[1], '快篩剩餘:', col[7])
說明:
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up