카테고리 없음

day 5-3 python 높은점수 구하기

karatejin 2023. 2. 27. 16:17

리스트 내부에서 높은 점수를 찾아 출력하기

단 max() 함수를 쓰지 않고 출력할 것

Instructions

You are going to write a program that calculates the highest score from a List of scores.

e.g. student_scores = [78, 65, 89, 86, 55, 91, 64, 89]

Important you are not allowed to use the max or min functions. The output words must match the example. i.e

The highest score in the class is: x

Example Input

78 65 89 86 55 91 64 89

In this case, student_scores would be a list that looks like: [78, 65, 89, 86, 55, 91, 64, 89]

Example Output

The highest score in the class is: 91

기본 조건

## max() 함수를 쓰지 말것
## min() 함수도 쓰지 말것

# 🚨 Don't change the code below 👇
student_scores = input("Input a list of student scores ").split()
for n in range(0, len(student_scores)):
    student_scores[n] = int(student_scores[n])
print(student_scores)
# 🚨 Don't change the code above 👆

#Write your code below this row 👇

 

나의 코드

max_number = student_scores[0]

for number in student_scores[1:]:
    if number > max_number:
        max_number = number
print(f"The highest score in the class is : {max_number}")

다른 방법

hightest_score = 0
for score in student_scores:
    if score > hightest_score:
        hightest_score = score
print(hightest_score)