2019-01-03 day8 作業(yè)

1.添加學(xué)生:輸入學(xué)生信息,將輸入的學(xué)生的信息保存到all_students中

all_students = [
{'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
{'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
{'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
{'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},]
new_name = input('姓名:')
new_age = input('年齡:')
new_score = input('成績(jī):')
new_tel = input('電話:')
new_student = {'name':new_name, 'age':new_age ,'score':new_score, 'tel':new_tel}
all_students.append(new_student)
print(all_students)

2.按姓名查看學(xué)生信息:

all_students = [
{'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
{'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
{'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
{'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},]
new_name = input('姓名:')
for studet in all_students:
    if studet['name'] == new_name:
        print(studet)

3.求所有學(xué)生的平均成績(jī)和平均年齡

 all_students = [
    {'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
    {'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
    {'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
    {'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},]
    sum_score = 0
    sum_age =0
    for student in all_students:
        sum_score += student['score']
        sum_age += student['age']
    print('平均成績(jī):',sum_score / len(all_students) , '平均年齡:',sum_age / len(all_students))

4.刪除班級(jí)中年齡小于18歲的學(xué)生

all_students = [
    {'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
    {'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
    {'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
    {'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},]
index = 0
for student in all_students:
    index += 1
    if student['age'] < 18:
        del all_students[index-1]
print(all_students)

5.統(tǒng)計(jì)班級(jí)中不及格的學(xué)生的人數(shù)

all_students = [
    {'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
    {'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
    {'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
    {'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},]
index = 0
for student in all_students:
    if student['score'] < 60:
        index += 1
print(index)

6.打印手機(jī)號(hào)最后一位是2的學(xué)生的姓名

all_students = [
    {'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
    {'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
    {'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
    {'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},]
index = 0
for student in all_students:
    if student['tel'][-1] == '2':
        print(student['name'])
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 使用一個(gè)變量all_students保存一個(gè)班的學(xué)生信息(4個(gè)),每個(gè)學(xué)生需要保存:姓名、年齡、成績(jī)、電話 1.添...
    woming閱讀 168評(píng)論 0 0
  • 作業(yè)# 使用一個(gè)變量all_students保存一個(gè)班的學(xué)生信息(4個(gè)),每個(gè)學(xué)生需要保存:姓名、年齡、成績(jī)、電話...
    多多爸是小白閱讀 217評(píng)論 0 0
  • 使用一個(gè)變量all_students保存一個(gè)班的學(xué)生信息(4個(gè)),每個(gè)學(xué)生需要保存:姓名、年齡、成績(jī)、電話 1.添...
    LittleBear_6c91閱讀 230評(píng)論 0 1
  • 文/水木清 近年來(lái),米叔的電影火爆,《神秘巨星》創(chuàng)下七點(diǎn)四億的好成績(jī),而《摔跤吧!爸爸》更是創(chuàng)下了12.93的票房...
    剎那年華之水木清閱讀 334評(píng)論 2 7
  • 曾經(jīng)的冥思苦想 被感悟 凝結(jié)成絢爛的真諦 一旦意識(shí)到荒謬 便已經(jīng)被鮮血和淚灌滿 所謂的成熟 或許會(huì)被仰望的星空 鋪...
    冷冬年閱讀 193評(píng)論 0 1

友情鏈接更多精彩內(nèi)容