Python 7 Levels, L4, Unit 31, More Operations on List

Powered By EmbedPress

Exercise:

number = int(input("Please input how many students:"))
score_list = []
for i in range(number):
    score = int(input("Please input score of the student "+str(i+1)+":"))
    score_list.append(score)

scores_greater_equal_60=[]
scores_less_60=[]

for i in score_list:
    if i >= 60:
        scores_greater_equal_60.append(i)
    else:
        scores_less_60.append(i)
print("Scores less than 60:", scores_less_60)
print("Scores greater than or equal 60:",scores_greater_equal_60)

Homework:

number = int(input("Please input how many students:"))
name_list = []
for i in range(number):
    name = input("Please input name of the student "+str(i+1)+":")
    name_list.append(name)

while True:
	name = input("Please input student name you are looking for(Q/q to quit):")
	if name == "Q" or name == "q":
		print("Abort system.")
		break
	elif name in name_list:
		print("The No. of " + name + " is: ",name_list.index(name))
	else:
		print(name," does not exist.")

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts