【正文】
L1[1])) (int(L1[2]))()print(專業(yè)課1的總平均分為,calAvg(L2))print(專業(yè)課2的總平均分為,calAvg(L3))參考答案:def calAvg(L): sum,count=0,0 for score in L: sum+=score count+=1 avg_score=int(sum/count) return avg_score3. 用函數(shù)或函數(shù)的遞歸實(shí)現(xiàn)求n!的算法。請(qǐng)輸入一個(gè)要插入的整數(shù):39。,fact(n))參考答案:def fact(n): value=1 for count in range(1,n+1): value*=countreturn value或def fact(n): if n==1: value=1 else: value=n*fact(n1) return value程序復(fù)雜度為O(n).4.主程序中已有一個(gè)排好序的列表,請(qǐng)編寫函數(shù)insertList,將從鍵盤接收的整數(shù)按原來(lái)從小到大的排序規(guī)律插入到該列表中。參考答案:def shushu(n): import mathi,w=2,0if n=1: w=1 while i = int((n)) and w==0: if n%i == 0: w = 1 break else: i = i+1 return wn=int(input(39??崭竦膫€(gè)數(shù)為:39。 39。Z39。 39。a39。)while len(num_str) != 0: (int(num_str)) num_str=input(39。參考答案:選擇排序:def bubble(List): num=len(List) for i in range(0,num1): for j in range(i+1,num): 對(duì)應(yīng)列表中的位置 if List[i]List[j]: List[i],List[j]=List[j],List[i] return ListL1=[]num_str=input(39。參考答案:f=open()L1=()f2=open(,39。班級(jí)總平均分為%d分。)else:print(上海這周未入春。))lt=(()).strip() 此處再讀第二行L2=list((39。第二天早上又將剩下的桃子吃掉一半,又多吃了一個(gè)。請(qǐng)輸入一個(gè)數(shù):39。參考答案:num=7while True: guess=int(input(39。elif score = 70: 無(wú)需寫小于什么什么的 因?yàn)閑lif就已經(jīng)是除了這個(gè)之外的了 grade = 39。60分以下為39。其中,90分以上為39。參考代碼:x = int(input(Please enter first integer: ))y = int(input(Please enter second integer: ))if (x == y): print(兩數(shù)相同!)elif (x y): print(較大數(shù)為:,x)else: print(較大數(shù)為:,y)。(1) 能被4整除但不能被100整除。C39。A39。E39。下圖為參考流程圖)參考答案:import mathn=int(input(請(qǐng)輸入一個(gè)數(shù):))x=int((n))i,w=2,0for i in range (2,x+1): if n%i==0: w=1if w==1: print(n,不是素?cái)?shù)。編程,找出1000之內(nèi)的所有完數(shù),并輸出該完數(shù)及對(duì)應(yīng)的因子。其中,第一行為最高氣溫,第二行為最低氣溫。))lt=(()).strip()L2=list((39。w39。班級(jí)總平均分為%d分。(3)找出兩門課的平均分在90分以上的學(xué)生,輸出他們的學(xué)號(hào)和各科成績(jī)。排序后結(jié)果:39。請(qǐng)查找最高分和最低分的學(xué)生,并在屏幕上顯示其學(xué)號(hào)和成績(jī)。 and s[i]=39。: digit+=1 else: other+=1print(字母數(shù):%d\n空格數(shù):%d\n數(shù)字?jǐn)?shù):%d\n其他字符數(shù):%d\n%(letters,space,digit,other))或p=input(39。 and i=39。): c+=1 else: d+=1print (39。+str(d))或letter,space,digit,other=0,0