Python 題目

PROBLEM

list comprehension(filter篩選)

#python #程式碼

scores = (50,60,60,40,80)

# s 表示內容, for s in scores 表示s 是 scores裡面的內容, if s >=60 表示條件
p = [s for s in scores if s >=60]

print(p)
print(len(p))

example:

chinese = int(input())
english = int(input())
math = int(input())

total = chinese + english + math
avg = total / 3

cnt = 0

if len([s for s in (chinese,english,math) if s >= 90]) >= 2:
  rank = "A"
else:
  rank = "B"

print(f'總分:{total}, 平均:{avg:.0f}, 等級:{rank}')