#第一題:根據成績輸出評分
s = float(input("請輸入成績:"))
if s >= 90:
print("a")
elif 89>= s >=80:
print("b")
elif 79>= s >=70:
print("c")
elif 69>= s >=60:
print("d")
elif 60>= s >=0:
print("e")
else:
print("您輸入有誤!")
#第二題:根據預設數讓使用者猜一猜預設樹並進行提示
x = 8
y = 0
while y != x:
a = int(input("猜一猜會是幾?"))
y = a
if x>a:
print("有點小了,可以猜大一點")
elif xprint("有點大了,可以猜小一點")
print("恭喜你猜對了!")
#第四題:輸出1000以內的素數以及這些素數之和
from math import sqrt
def ss(i):
for y in range(2,int(sqrt(i))+1):
if i%y == 0:
return false
print(i,end=' ')
return i
count = 0
for i in range(2,1001):
if ss(i):
count += i
print('')
print(f'1000以內素數合為')
#第五題:輸入乙個時間(小時:分鐘:秒),輸入該時間經過5分30秒後的時間
new_t =
t1 = t.split(':')
for i in t1:
h = new_t[0]
m = new_t[1]
s = new_t[2]
if ((h >= 0) and (h <24) ) and ((m>= 0) and (m <=60)) and ((s>= 0) and (s <=60)):
s +=30
if s >= 60:
s = s-60
m+=1
m+=5
if m >= 60:
m = m-60
h+=1
if h ==24:
h = 0
print (f'相加後的時間為:::')
#第六題:編寫程式,按公式s = 1**2+2**2+3**2+4**2+n**2求累加和s不超過1000的最大項數n。
n = 1
s = 0
print('n s')
while s<1000:
s = n**2+s
print(f' ')
n += 1
第三章練習題
3.1重量計算。月球上物體的體重是在地球上的16.5 假如你在地球上每年增長0.5kg,編寫程式輸出未來10年你在地球和月球上的體重狀況。weight eval input 請輸入您的體重 kg for i in range 1 11 weight earth weight 0.5 i weight...
opencv課後練習 第三章節2 4
題目2 建立乙個三通道二維矩陣,位元組型別,大小為100 100,並設定所有數值為0 a.在矩陣中使用void cvcircle cvarr img,cvpoint center,intradius,cvscalar color,int thickness 1,int line type 8,int...
c prime 第三章 向量練習題答案
c prime 第三章 字串 向量和陣列練習題答案 vector a vectorint ivec ivec 儲存vector物件 b vector svec ivec 錯誤,ivec的物件是int svec的物件是string。c vector svec 10 null 構造了10個 null 字...