[Python] Zybooks 5.19 LAB: Golf scores

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am having problems with writing a Python code for my Zybooks Lab and need some help. Here is the question.


    Golf scores record the number of strokes used to get the ball in the hole. The expected number of strokes varies from hole to hole and is called par (i.e. 3, 4, or 5). Each score's name is based on the actual strokes taken compared to par:

    • "Eagle": number of strokes is two less than par
    • "Birdie": number of strokes is one less than par
    • "Par": number of strokes equals par
    • "Bogey": number of strokes is one more than par

    Given two integers that represent par and the number of strokes used, write a program that prints the appropriate score name. Print "Error" if par or score is not in the expected range.
    ​

    I have looked for help and their are answers to the question. However, they are using characters I have not used yet and do not want to get in trouble for using them. Or written in C+.

    strokes = int(input())
    par = int(input())

    if (par != 3 and par != 4 and par != 5:
    print('Error')

    elif (strokes <= par - 2):
    print('Eagle')
    elif (strokes <= par -1):
    print('Birdie')
    elif (strokes == par):
    print('Par')
    else:
    print('Bogey')


    these are the answers I am getting.

    1. Input
    4
    3
    Your output
    Par
    Expected output
    Birdie

    2. Input
    5
    3
    Your output
    Par
    Expected output
    Eagle

    3. Input
    5
    5
    Your output
    Par (correct)

    4.Input
    5
    6
    Your output
    Par
    Expected output
    Bogey

    5:Input
    1
    2
    Your output
    Error (correct)

    Continue reading...

Compartilhe esta Página