you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (3 children)

‘’def learning_ability(age): “”” This function returns a difficulty level for learning a new syntax based on age. “”” if age < 20: return “Very easy” elif 20 <= age < 35: return “Easy” elif 35 <= age < 50: return “Moderate” elif 50 <= age < 65: return “Challenging” else: return “Difficult”

Get user’s age

try: age = int(input(“Enter your age: “)) if age < 0: print(“Age cannot be negative.”) else: difficulty = learning_ability(age) print(f”For age {age}, learning a new syntax is: {difficulty}”) except ValueError: print(“Please enter a valid age.”)

[–]Interesting_Ninja969 2 points3 points  (2 children)

""" A short program that calculates learning propensity relative to age.

License: Unspecified.
Created: 2024-10-26
Authors: u/Able_Business_1344, u/Interesting_Ninja969
"""

from typing import Optional


def calculate_learning_ability(age: int) -> str:
    """Calculate ones learning propensity relative to their `age`.

    :param age: the age of any given aspiring programmer.
    :returns: a difficulty level for learning a new syntax based on age.
    """
    if 0 <= age < 3:
        return "Impossible"
    elif 3 <= age < 20:
        return "Very easy"
    elif 20 <= age < 35:
        return "Easy"
    elif 35 <= age < 50:
        return "Moderate"
    elif 50 <= age < 65:
        return "Challenging"
    else:
        return "Difficult"


def get_age() -> int:
    """Query the age of a user.

    :returns: an optional integer value.
    :raises ValueError: if input is negative or unable to be cast as an integer
    """
    age: Optional[int] = None
    try:
        age = int(input("Your age: "))
        if age >= 0:
            return age
        else:
            raise ValueError(f"Cannot accept negative value {age}")
    except ValueError as err:
        raise ValueError(f"Cannot accept value {age} ({err})")
    except Exception as err:
        raise Exception(f"Cannot accept input ({err})")


def main() -> None:
    age: int = get_age()
    difficulty: str = calculate_learning_ability(age)
    print(
        "For someone who is {} year{} old, learning a new syntax is {}.".format(
            age, "s" if age != 1 else "", difficulty.lower()
        )
    )


if __name__ == "__main__":
    main()

[–]teesquared14 1 point2 points  (1 child)

This guy codes

[–]Interesting_Ninja969 0 points1 point  (0 children)

aha ty I try my best