Professional Documents
Culture Documents
print('學號:28825252')
print('姓名:打了沒')
print('我的星座是天蠍座')
print('計算機程式老師是曾文宏')
print('我愛南臺')
input()
HW2
print('12345678 曾文宏')
f1 = eval(input('請輸入一個浮點數: '))
f2 = eval(input('請輸入另一個浮點數: '))
#計算兩數的總和及平均數
total = f1 + f2
average = total / 2
#印出兩浮點數、總和及平均數
print()
print('浮點數 1 =', f1, '浮點數 2 =', f2)
print('總和為 ', total)
print('平均數為 ', average)
input()
HW3
print('12345678 曾文宏')
input()
HW4
print('12345678 曾文宏')
print()
print('華氏', f, '度換算成攝氏', c,'度')
print(f'華氏 {f} 度換算成攝氏 {c} 度')
print('華氏 %d 度換算成攝氏 %d 度' % (f, c))
print('華氏 {0} 度換算成攝氏 {1} 度'.format(f, c))
print()
print()
print('攝氏', c, '度換算成華氏', f,'度')
print(f'攝氏 {c} 度換算成華氏 {f} 度')
print('攝氏 %d 度換算成華氏 %d 度' % (c, f))
print('攝氏 {0} 度換算成華氏 {1} 度'.format(c, f))
input()
HW5
print('12345678 曾文宏')
s = eval(input('請輸入正三角形的邊長:'))
height = 3**0.5 / 2 * s # 計算高
area = 3**0.5 / 4 * s**2 # 計算面積
print('正三角形的邊長:', s) # 印出邊長
print('正三角形的高 =', round(height, 2)) # 印出高
print('正三角形的面積 =', round(area, 2)) # 印出面積
input()
HW6
print('12345678 曾文宏')
x = eval(input('請輸入分鐘數:')) # 輸入 x 值
y = eval(input('請輸入秒數:')) # 輸入 y 值
z = eval(input('請輸入公里數:')) # 輸入 z 值
hour = x / 60 + y / 60 / 60 # 把分和秒換算成小時
mile = z / 1.6 # 把公里換算成英里
speed = mile / hour # 計算速度
print('速度 =', round(speed, 2), '英哩/小時') # 印出速度
input()
HW7
print('12345678 曾文宏')
input()
HW8
print('12345678 曾文宏')
import math
n = eval(input('請輸入多少邊的邊形: '))
s = eval(input('請輸入邊長: '))
area = (n * pow(s, 2)) / (4 * math.tan(math.pi/n))
print('面積為: %.2f' % area)
input()
HW9
print('12345678 曾文宏')
input()
HW10
print('12345678 曾文宏')
import math
input()
HW11
print('12345678 曾文宏')
income = eval(input('\n 請輸入你的所得: '))
input()
HW12
print('12345678 曾文宏')
input()
HW13
print('12345678 曾文宏')
input()
HW14
print('12345678 曾文宏')
n=1
while n**3 < 12000:
n += 1
print('三次方小於 12,000 的最大整數 = %d'% (n-1))
input()
HW15
print('12345678 曾文宏')
rope = float(input("請輸入繩子長度(公尺):"))
count = 0
while rope >= 0.2:
rope = rope / 2
count = count + 1
print("共需對折", count, "次")
input()
HW16
print('12345678 曾文宏')
count = 0
total = 0
positive = 0
negative = 0
num = eval(input('\n 請輸入一整數: '))
while num != 0:
count += 1
total += num
if num > 0:
positive += 1
else:
negative += 1
num = eval(input('請輸入一整數: '))
HW17
print('12345678 曾文宏')
input()
HW18
print('12345678 曾文宏')
import math
total = 0
for i in range(1, 625):
total += 1/(math.sqrt(i) + math.sqrt(i+1))
print('\ntotal = %.2f' % total)
input()
HW19
print('12345678 曾文宏')
total = 0
input()
HW20
print('12345678 曾文宏')
count = 1
print()
for year in range(2001, 2101):
cond1 = year % 400 == 0
cond2 = year % 4 == 0
cond3 = year % 100 != 0
if (cond1) or (cond2 and cond3):
if count % 10 == 0:
print(year)
else:
print(year, end = ' ')
count += 1
input()
HW21
print('12345678 曾文宏')
count = 0
year1 = eval(input('請輸入一西元年份: '))
year2 = eval(input('請輸入另一西元年份: '))
year = year1
print()
#若 count 是 5 的倍數,則跳行
if count % 5 == 0:
print()
year += 1
input()
HW22
print('12345678 曾文宏')
print()
for i in range(1,7):
for j in range(1,i+1):
print(j, end = "")
print()
print()
for i in range(6,0,-1):
for j in range(1,i+1):
print(j, end = "")
print()
print()
for i in range(1,7):
for j in range(i,0,-1):
print(j, end = "")
print()
print()
for i in range(6,0,-1):
for j in range(i,0,-1):
print(j, end = "")
print()
input()
HW23
print('12345678 曾文宏')
import random
def randomNum():
evenNum = 0
for i in range(1, 101):
num = random.randint(1, 100)
if num % 2 == 0:
evenNum += 1
print('%3d(%2d) '%(num, evenNum), end = '')
else:
print('%3d '%(num), end = '')
if i % 10 == 0:
print()
return evenNum
def main():
n = randomNum()
print('\n100 個亂數中偶數有 %d 個'%(n))
main()
input()
HW24
print('12345678 曾文宏')
def mi(i):
total = 0
for x in range(1, i+1):
total += x/(x+1)
return total
def mimi(i):
total = 0
for x in range(1, i+1):
total += x/(x+1)
print('%2d %7.4f'%(i, total))
def main():
print()
print('%2s %6s'%('i', 'mi(i)'))
for i in range(1, 21):
value = mi(i)
print('%2d %7.4f'%(i, value))
print()
print('%2s %6s'%('i', 'mi(i)'))
for i in range(1, 21):
mimi(i)
main()
input()
HW25
print('12345678 曾文宏')
def pi(i):
total = 0
for x in range(1, i+1):
total += 4*((-1)**(x+1) / (2*x-1))
return total
def main():
print('%-2s %5s'%('i', 'pi(i)'))
for j in range(1, 902, 100):
t = pi(j)
print('%-3d %7.4f'%(j, t))
main()
input()
HW26
print('12345678 曾文宏\n')
import random
numGt90 = 0
for i in range(1, 101):
randomNum = random.randint(1, 100)
if randomNum > 90:
numGt90 += 1
print('%3d* '%(randomNum), end = '')
else:
print('%3d '%(randomNum), end = '')
if i % 10 == 0:
print()
input()
HW27
print('12345678 曾文宏\n')
import random
lst = []
for i in range(100):
randomNum = random.randint(1, 100)
lst.append(randomNum)
if (i+1) % 10 == 0:
print('%3d '%(randomNum))
else:
print('%3d '%(randomNum), end = '')
min = lst[0]
index = 0
for j in range(1, 100):
if lst[j] < min:
min = lst[j]
index = j
input()
HW28
print('12345678 曾文宏\n')
input()
HW29
print('12345678 曾文宏\n')
input()
HW30
print('12345678 曾文宏\n')
print('你有優惠嗎?', ans)
input()
HW31
print('12345678 曾文宏\n')
input()
HW32
print('12345678 曾文宏\n')
def main():
s = input("Enter a string: ").strip()
ch = input("Enter a character: ").strip()
print(ch, '出現的次數為', count(s, ch))
main()
input()
HW33
print('12345678 曾文宏\n')
# Calculate checksum
sum = 0
for i in range(12):
sum += int(number[i]) * (1 if i % 2 == 0 else 3)
checksum = 10 - sum % 10
if checksum == 10:
checksum = 0
input()
HW34
print('12345678 曾文宏\n')
def area(c1,c2,c3):
'計算三角形面積'
a = ((c1[0] - c2[0])**2 + (c1[1] - c2[1])**2) ** 0.5
b = ((c2[0] - c3[0])**2 + (c2[1] - c3[1])**2) ** 0.5
c = ((c3[0] - c1[0])**2 + (c3[1] - c1[1])**2) ** 0.5
s = (a+b+c)/2
abc = (s*(s-a)*(s-b)*(s-c)) ** 0.5
return round(abc, 1)
input()
HW35
print('12345678 曾文宏\n')
id_no = input("請輸入身份證字號:")
ans = '168' in id_no
print('你有優惠嗎?', ans)
input()
MID1
print('12345678 曾文宏')
num_hr = eval(input('請輸入停車時數?'))
if num_hr <= 2:
total_fee = num_hr * 50
elif num_hr <= 4:
total_fee = (num_hr - 2) * 45 + 50 * 2
elif num_hr <= 6:
total_fee = (num_hr - 4) * 40 + 50 * 2 + 45 * 2
elif num_hr <= 8:
total_fee = (num_hr - 6) * 35 + 50 * 2 + 45 * 2 + 40 * 2
else:
total_fee = (num_hr - 8) * 30 + 50 * 2 + 45 * 2 + 40 * 2 + 35 * 2
input()
MID2
print('12345678 曾文宏')
import random
even_num = 0
odd_num = 0
even_total = 0
odd_total = 0
input()
MID3
print('12345678 曾文宏')
salary01 = eval(input('\n 請輸入月薪:'))
salary02 = eval(input('請輸入目標月薪:'))
pay = salary01
count = 0
input()
MID4
print('12345678 曾文宏')
area = round((s*(s-a)*(s-b)*(s-c))**0.5, 2)
print('此三角形的面積為:', area)
input()
QUIZ1
print('12345678 曾文宏')
input()