Docsity

2 Problems on Computer Programming - Homework 2 | CSC 1310, Assignments of Computer Science

Toggle sidebar
bg1
Assignment 2
Csc 1310 Spring 2009
1. Given an any size list called aa, which contains students’ scores, please use for loop to
write a program to calculate the average score, lowest score, and the highest score. Also,
you need to count the number of students who didn’t pass the exam (score < 60). When
running the program, the output should be as follows (100 pts).
>>> python ass2.py
The average score is: 61.8888888889.
The lowest score is: 30.
The highest score is: 90.
The number of failed students is: 4.
score=[34, 56, 79, 90, 30, 60, 50,75, 83]
sum=0.0
min=score[0]
max=score[0]
number=0
for i in score:
if i>max:
max=i
if i<min:
min=i
if i<60:
number=number+1
sum=sum+i
avg=sum/len(score)
print "The average score is: "+str(avg)+"."
print "The lowest score is: "+str(min)+"."
print "The highest score is: "+str(max)+"."
print "The number of failed students is: "+str(number)+"."
pf2

Partial preview of the text

Download 2 Problems on Computer Programming - Homework 2 | CSC 1310 and more Assignments Computer Science in PDF only on Docsity!

Assignment 2 Csc 1310 Spring 2009

  1. Given an any size list called aa, which contains students’ scores, please use for loop to write a program to calculate the average score, lowest score, and the highest score. Also, you need to count the number of students who didn’t pass the exam (score < 60). When running the program, the output should be as follows (100 pts).

python ass2.py The average score is: 61.8888888889. The lowest score is: 30. The highest score is: 90. The number of failed students is: 4. score=[34, 56, 79, 90, 30, 60, 50,75, 83] sum=0. min=score[0] max=score[0] number= for i in score: if i>max: max=i if i<min: min=i if i<60: number=number+ sum=sum+i avg=sum/len(score) print "The average score is: "+str(avg)+"." print "The lowest score is: "+str(min)+"." print "The highest score is: "+str(max)+"." print "The number of failed students is: "+str(number)+"."

  1. Given an any size list called aa, please use For loop to SORT all values (from large to small) in aa, and store the sorted values in another list bb. (Extra credit: 50pts). ( Do NOT use sort() method!!!) aa=[11,22,33,44,0,53,57,23] #any list bb=[] total_num=len(aa) for i in range(total_num): max= for j in range(len(aa)): if aa[j]>max: max=aa[j] bb.append(max) aa.remove(max) print bb print aa