Você está na página 1de 2

Answers for S15 Computer Science IGCSE; python

students = 30
names = []
weight = []
i=0
while i < students:
print("enter Student", i, "'s details: ")
names.insert(i, input("name: "))
valid = 0
while valid == 0:
print("Enter ", names[i], "'s weight: ")
weight.insert(i, int(input("weight ")))
if weight[i] > 10 and weight[i] < 200:
valid = 1
else:
print("You entered invalid weight, please try again.")
i += 1
i=0

weight2 = []
difference = []
i=0
print("enter the Student's weight for the last day of the term")
while i < students:
valid = 0
while valid == 0:
print("Enter ", names[i], "'s weight: ")
weight2.insert(i, int(input("weight ")))
if weight2[i] > 10 and weight2[i] < 200:

valid = 1
else:
print("You entered invalid weight, please try again.")
i += 1
i=0
while i < students:
x = weight2[i] - weight[i]
difference.insert(i, x)
i += 1
i=0
while i < students:
print("Student", i, "'s name: ", names[i])
print(names[i], "'s weight:", weight[i])
if difference[i] > 2.5 or difference[i] < -2.5:
if difference[i] >= 0:
print("Student", names[i], "has gained ", difference[i], "kg")
else:
print("Student", names[i], "has lost ", -difference[i], "kg")
else:
print(names[i], "has lost less than 2.5 kg")
i += 1

Você também pode gostar