Python_Matter/Solve

Python Learn the basics Quiz 42

AnKiWoong 2019. 6. 9. 13:28
반응형

Q>

You are given the current stock prices. You have to find out which stocks cost more.

(현재 주식 가격이 주어집니다. 어떤 주식이 더 많이 들었는지 알아야합니다.)

 

Input: The dictionary where the market identifier code is a key and the value is a stock price.

         (시장 식별자 코드가 키이고 값이 주가 인 딕셔너리.)

 

Output: A string and the market identifier code.

          (문자열과 시장 식별자 코드.)

 

Example:

best_stock({
    'CAC': 10.0,
    'ATX': 390.2,
    'WIG': 1.2
}) == 'ATX'
best_stock({
    'CAC': 91.1,
    'ATX': 1.01,
    'TASI': 120.9
}) == 'TASI'

 

Preconditions: All the prices are unique.(모든 가격은 고유합니다.)

 

A>

def best_stock(data):
    # your code here
    max_price = 0
    # answer 키
    answer = ''
    # data -> s(주식의 가격)
    for i in data:
        # max_price 보다 크면 대체
        if data[i] > max_price:
            max_price = data[i]
            answer = i

    return answer

if __name__ == '__main__':
    print("Example:")
    print(best_stock({
        'CAC': 10.0,
        'ATX': 390.2,
        'WIG': 1.2
    }))

    # These "asserts" are used for self-checking and not for an auto-testing
    assert best_stock({
        'CAC': 10.0,
        'ATX': 390.2,
        'WIG': 1.2
    }) == 'ATX', "First"
    assert best_stock({
        'CAC': 91.1,
        'ATX': 1.01,
        'TASI': 120.9
    }) == 'TASI', "Second"
    print("Coding complete? Click 'Check' to earn cool rewards!")

 

O>

Example:
ATX
Coding complete? Click 'Check' to earn cool rewards!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형