導航:首頁 > 編程語言 > python編程教師考察試題

python編程教師考察試題

發布時間:2022-07-23 07:28:50

python編程題,求教!!

代碼如下

"""
學生成績表
姓名語文數學英語總分
王敏95.598
利用字典顯示上表內容
"""

header=['姓名','語文','數學','英語','總分','平均分']
score=[
{
'name':'王敏',
'Chinese':95.5,
'Math':98,
'English':97,
},
{
'name':'劉志堅',
'Chinese':96,
'Math':92,
'English':82,
},
{
'name':'謝塞科',
'Chinese':91,
'Math':100,
'English':90,
},
{
'name':'肖江秋',
'Chinese':88,
'Math':93,
'English':99,
}
]

#輸出表格

print('學生成績表')
blank=' '
little_blank=' '
Chinese_max={'name':'','sorce':0}#語文
Math_max={'name':'','sorce':0}#數學
English_max={'name':'','sorce':0}#英語

forvinheader:
print(v,end=blank)

forvinscore:
print()

ifChinese_max['sorce']==0:
Chinese_max['sorce']=v['Chinese']
else:
#對比分數
ifChinese_max['sorce']<v['Chinese']:
Chinese_max['sorce']=v['Chinese']
Chinese_max['name']=v['name']
ifChinese_max['name']=='':
Chinese_max['name']=v['name']

ifMath_max['sorce']==0:
Math_max['sorce']=v['Math']
else:
#對比分數
ifMath_max['sorce']<v['Math']:
Math_max['sorce']=v['Math']
Math_max['name']=v['name']
ifMath_max['name']=='':
Math_max['name']=v['name']

ifEnglish_max['sorce']==0:
English_max['sorce']=v['English']
else:
#對比分數
ifEnglish_max['sorce']<v['English']:
English_max['sorce']=v['English']
English_max['name']=v['name']
ifEnglish_max['name']=='':
English_max['name']=v['name']

print(v['name'],end='')
iflen(v['name'])>2:
print(end=little_blank)
else:
print(end=blank)

print(v['Chinese'],end='')
if'.'instr(v['Chinese']):
print(end=little_blank)
else:
print(end=blank)

print(v['Math'],end='')
if'.'instr(v['Math']):
print(end=little_blank)
else:
print(end=blank)

print(v['English'],end='')
if'.'instr(v['English']):
print(end=little_blank)
else:
print(end=blank)

total=v['Chinese']+v['Math']+v['English']
print(total,end='')
if'.'instr(total):
print(end=little_blank)
else:
print(end=blank)

print(round(total/3),end='')#平均分

#每科最高分

print(' 最高分')
print('語文 '+Chinese_max['name']+' '+str(Chinese_max['sorce']))
print('數學 '+Math_max['name']+' '+str(Math_max['sorce']))
print('英語 '+English_max['name']+' '+str(English_max['sorce']))

輸出如下

學生成績表
姓名 語文 數學 英語 總分 平均分
王敏 95.5 98 97 290.5 97
劉志堅 96 92 82 270 90
謝塞科 91 100 90 281 94
肖江秋 88 93 99 280 93

最高分
語文 劉志堅 96
數學 謝塞科 100
英語 肖江秋 99

輸出截圖

⑵ 關於python程序設計題的題庫

1、average_sum函數的功能為求一批數中大於平均值

sum=0
k=0
for i in range(n):
sum=sum+a[i]
average=sum/n
for i in range:
if(a[i]>average):
k=k+a[i]
return k

2、編寫函數fun求一個不多於五位數的正整數的位數

if(m>9999):
place=5
elif(m>999):
place=4
elif(m>99):
place=3
elif(m>9):
place=2
else:
place=1
return place

3、請編fun函數,求4*4整形數組的主對角線元素的和

sum=0.0
for i in range(4):
sum+=a[i][i]
return sum

4、已知:一元錢一瓶汽水,喝完後兩個空瓶換一瓶汽水。問:請輸入錢數(大於1的正整數),則根據錢數最多可以喝到幾瓶汽水。

s=0
k=0
while m>0:
m=m-1
s=s+1
k=k+1
while k>=2:
k=k-2
s=s+1
k=k+1
return s

5、編寫函數fun(x,y),函數的功能是若x、y為奇數,求x到y之間的奇數和;若x、y為偶數,則求x到y之間的偶數和。要求必須使用for結構。
主函數的功能是分別計算如下的值:
(1+3+5+……+777)+(2+4+6+……+888)=???
(1+3+5+……+1111)+(2+4+6+……+2222)=???
(1+3+5+……+1999)+(2+4+6+……+1998)=???

s=0
for i in range(x,y+1,2):
s=s+i
return s

6、編寫函數main 求3!+6!+9!+12!+15!+18!+21!
s=0
for i in range(3,22,3):
r=1
for j in range(1,i+1):
r*=j
s+=r
print(s)

⑶ 求助python編程的題目

def count(val, seq):
"""
>>> count(5, (1, 5, 3, 7, 5, 8, 5))
3
>>> count('s', 'Mississippi')
4
>>> count((1, 2), [1, 5, (1, 2), 7, (1, 2), 8, 5])
2
"""
return list(seq).count(val)

def reverse(seq):
"""
>>> reverse([1, 2, 3, 4, 5])
[5, 4, 3, 2, 1]
>>> reverse(('shoe', 'my', 'buckle', 2, 1))
(1, 2, 'buckle', 'my', 'shoe')
>>> reverse('Python')
'nohtyP'
"""
return seq[::-1]

def sort_sequence(seq):
"""
>>> sort_sequence([3, 4, 6, 7, 8, 2])
[2, 3, 4, 6, 7, 8]
>>> sort_sequence((3, 4, 6, 7, 8, 2))
(2, 3, 4, 6, 7, 8)
>>> sort_sequence("nothappy")
'ahnoppty'
"""
if type(seq) == str:
return ''.join(sorted(seq))
else:
return type(seq)(sorted(seq))

def recursive_min(nested_num_list):
"""
>>> recursive_min([2, 9, [1, 13], 8, 6])
1
>>> recursive_min([2, [[100, 1], 90], [10, 13], 8, 6])
1
>>> recursive_min([2, [[13, -7], 90], [1, 100], 8, 6])
-7
>>> recursive_min([[[-13, 7], 90], 2, [1, 100], 8, 6])
-13
"""
smallest = nested_num_list[0]
while type(smallest) == type([]):
smallest = smallest[0]

for element in nested_num_list:
if type(element) == type([]):
min_of_elem = recursive_min(element)
if smallest > min_of_elem:
smallest = min_of_elem
else: # element is not a list
if smallest > element:
smallest = element
return smallest

def recursive_count(target, nested_num_list):
"""
>>> recursive_count(2, [2, 9, [2, 1, 13, 2], 8, [2, 6]])
4
>>> recursive_count(7, [[9, [7, 1, 13, 2], 8], [7, 6]])
2
>>> recursive_count(15, [[9, [7, 1, 13, 2], 8], [2, 6]])
0
>>> recursive_count(5, [[5, [5, [1, 5], 5], 5], [5, 6]])
6
"""
count = 0
for element in nested_num_list:
if type(element) == type([]):
count += recursive_count(target, element)
else: # element is not a list
if element == target:
count += 1
return count

def flatten(nested_num_list):
"""
>>> flatten([2, 9, [2, 1, 13, 2], 8, [2, 6]])
[2, 9, 2, 1, 13, 2, 8, 2, 6]
>>> flatten([[9, [7, 1, 13, 2], 8], [7, 6]])
[9, 7, 1, 13, 2, 8, 7, 6]
>>> flatten([[9, [7, 1, 13, 2], 8], [2, 6]])
[9, 7, 1, 13, 2, 8, 2, 6]
>>> flatten([[5, [5, [1, 5], 5], 5], [5, 6]])
[5, 5, 1, 5, 5, 5, 5, 6]
"""
flat_list = []
for element in nested_num_list:
if type(element) == type([]):
flat_list += flatten(element)
else: # element is not a list
flat_list.append(element)
return flat_list

if __name__ == "__main__":
import doctest
doctest.testmod()

----------------------------------
6 items passed all tests:
3 tests in __main__.count
4 tests in __main__.flatten
4 tests in __main__.recursive_count
4 tests in __main__.recursive_min
3 tests in __main__.reverse
3 tests in __main__.sort_sequence
21 tests in 7 items.
21 passed and 0 failed.
Test passed.
-----------------------------------------

LZ在自學這個把
http://www.openbookproject.net/thinkCSpy/
確實是好書

⑷ 求教兩道python編程題

defcount_words(input_str):
returnlen(input_str.split(''))
defcount_substr(input_str,sub_str):
returninput_str.count(sub_str)

使用系統函數就可以

⑸ 求助Python程序設計編程題!

按照題目要求編寫的Python程序如下


s=input("請輸入只包含字母的字元串:")

s=s.lower()

result={}

for i in s:

if i in result.keys():

result[i]+=1

else:

result[i]=1

print(result)


源代碼(注意源代碼的縮進)

⑹ Python面向對象編程題

classTime:
def__init__(self,hours,minutes,seconds):
self.__hours=hours
self.__minutes=minutes
self.__seconds=seconds

defhours(self):
returnself.__hours

defminutes(self):
returnself.__minutes

defseconds(self):
returnself.__seconds

def__add__(self,other):#定義加法行為
pass

def__sub__(self,other):#定義減法行為
pass

def__eq__(self,other):#定義等於號行為
pass

def__lt__(self,other):#定義小於號行為
pass

寫出大致框架,自行完善後面的四個魔法方法

⑺ 一道簡單的python編程題

這個是典型的遞歸函數例子,你們老師給這個題目,一般是在講解遞歸函數之後。所以最好使用遞歸函數解題。

⑻ Python編程題

defcount(s):
res={
'Upper':0,#數字
'Lower':0,#大寫
'Digit':0,#小寫
'Other':0#其他
}
forcins:
ifc.isdigit():
res['Digit']+=1
elifc.islower():
res['Lower']+=1
elifc.isupper():
res['Upper']+=1
else:
res['Other']+=1
returnres

####e.g.
count('vdCde123D3*&1')

>>>{'Digit':5,'Lower':4,'Other':2,'Upper':2}

⑼ Python編程筆試題,求大神解答


這就可以了

閱讀全文

與python編程教師考察試題相關的資料

熱點內容
歐洲cf玩什麼伺服器 瀏覽:527
如何連接另一台電腦上的共享文件夾 瀏覽:679
如何讓桌面文件夾搬家到e盤 瀏覽:71
java自動格式化 瀏覽:617
ipad怎麼查看文件夾大小 瀏覽:581
手工粘土解壓球 瀏覽:550
在線視頻教育源碼 瀏覽:39
快四十學什麼編程 瀏覽:754
gnumakelinux 瀏覽:537
視易峰雲伺服器怎麼改系統 瀏覽:535
javamap取值 瀏覽:768
mac和win磁碟加密軟體 瀏覽:474
蘋果為什麼會連接不到伺服器 瀏覽:726
pdf格式文件如何保存 瀏覽:303
小霸王伺服器tx什麼意思 瀏覽:75
解釋dns命令 瀏覽:584
dmx512怎麼編程 瀏覽:744
北京雲主機17t雲伺服器 瀏覽:232
php伺服器url地址 瀏覽:440
哪裡看書免費app 瀏覽:437