python练习题(列表)

# 有多个学生的成绩72,89,65,58,87,91,53,82,71,93,76,68
# a.计算并输出学生的平均成绩。
# b.统计各成绩等级(90分以上为‘A’,80~89分为‘B’,70~79分为‘C’,60~69分为‘D’,60分以下为E)学生人数。
student = [72,89,65,58,87,91,53,82,71,93,76,68]
sum = 0
# a.计算并输出学生的平均成绩。
for i in student:
    sum = sum + i
print(sum/len(student))

# b.统计各成绩等级
a=b=c=d=e=0
for i in student:
    if i/10<6:
        e = e + 1
    elif i/10<7:
        d = d + 1
    elif i/10<8:
        c = c + 1
    elif i/10<9:
        b = b + 1
    else:
        a = a + 1
print("A",a,"人","  B",b,"人","  C",c,"人","  D",d,"人","  E",e,"人")

# 考试成绩如下,输出需要补考的同学姓名:
# 姓名:"张晓林","王强","高文博","刘丽冰","李雅芳","张立华","曹雨生","李  芳","徐志华","李晓力","罗  明","段  平"
# 成绩:91.00,87.00,88.00,38.00,92.00,74.00,90.00,59.00,91.00,78.00,67.00,75.00
Name = ["张晓林","王强","高文博","刘丽冰","李雅芳","张立华","曹雨生","李  芳","徐志华","李晓力","罗  明","段  平"]
Grade = [91.00,87.00,88.00,38.00,92.00,74.00,90.00,59.00,91.00,78.00,67.00,75.00]

# 法一
for i in range(0,len(Grade)):
    if Grade[i]<60:
        print(Name[i])

# 法二
for n,g in zip(Name,Grade):
    if g<60:
        print(n)

#每次输入一个大于0的整数,当输入-1时结束,并输出所有的奇数,所有的偶数。
jishu = 0
oushu = 0
i = 1
while(i>=0 and i!=-1):
    i = int(input())
    if i>=0:
        if i%2==0:
            oushu = oushu + i
        else:
            jishu = jishu + i
    else:
        break

print("奇数:",jishu,"   偶数:",oushu)

#现在有一个列表只有一个元素100,然后开始输入整数x,把x按照升序存到列表中。
# 当输入-1时结束,输出列表。注意:当输入大于最大值时的情况。
list = [100]
x = int(input())
while x != -1 :
    if x > list[-1]:
        list.append(x)
    else:
        for i in range(0,len(list)):
            if x < list[i]:
                list.insert(i,x)
                break
    x=int(input())

print(list)

#有一个序列a存放的是1到100。然后开始输入整数x,每次删除a中能被x整除的数。
#当输入-1时结束,输出a中剩余的数。
a = [1]
for i in range(2,101):
    a.append(i)
x = int(input())
while(x!=-1):
    for j in a:
        if j % x == 0:
            a.remove(j)
    x = int(input())
print(a)

# 现在有两个列表,想合并为一个,请按照升序进行组合。
# 列表1:25,369,1478,54,2,36
# 列表2:6,258,14,36,47,2145
list1 = [25,369,1478,54,2,36]
list2 = [6,258,14,36,47,2145]
List = list1 + list2
List.sort()
print(List)
# 实在不想用这种作弊的方法

# 10个人围成一圈开始报数,每次数到3的倍数的人退出,请输出退出顺序。
# 第一轮: 3 6 9     剩下:1,2,4,5,7,8,10
# 第二轮: 2 7       剩下:1,4,5,8,10
# 第三轮: 1 8       剩下:4,5,10
# 第四轮: 5         剩下:4,10
# 第五轮: 10        剩下:4
# 第六轮: 4
List = [1,2,3,4,5,6,7,8,9,10]
num = 0
Sort = []
while len(List)!=0:
    Temp = []
    for i in List:
        num = num + 1
        if num%3 == 0:
            Temp.append(i)
            Sort.append(i)
    for j in Temp:
        List.remove(j)
print(Sort)

绝情的女朋友,在这里偷偷diss她一下

你可能感兴趣的:(Python)