老師,請我們寫一支小程式。 計算,學生的平均身高。
# 🚨 Don't change the code below 👇
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
# print(student_heights)
# 🚨 Don't change the code above 👆
#Write your code below this row 👇
Coding - Teacher Angela
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
total_height = 0
for height in student_heights:
total_height += height
print(f"total height = {total_height}")
number_of_students = 0
for student in student_heights:
number_of_students += 1
print(f"number of students = {number_of_students}")
average_height = round(total_height / number_of_students)
print(average_height)
Coding - Student Laurence
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
a = 0
for i in student_heights:
a += i
a = round(a / (n + 1))
print(a)
student_heights = input("Input a list of student heights ").split()
for n in range(0, len(student_heights)):
student_heights[n] = int(student_heights[n])
a = 0
b = 0
for i in student_heights:
a += i
b += 1
a = round(a / b)
print(a)
我在這一個練習題,卡住了一些時間。 我知道,要做什麼,但我卻不知道,該怎麼下手(coding)。
最後,靠強力隊友Tim的提示,才知道該由什麼方向著手。
我的邏輯思考,還有待加強。 How to think like a programmer?