答案:你是成年人吗?【难度:1级】--景越训练营Python习题答案(含多种解法)

你是成年人吗?【难度:1级】:

答案1:

def is_adult(age):
    return f"You're {age>17 and 'an adult' or 'a minor'}"​

答案2:

def is_adult(age):
    return 'You\'re an adult' if age >= 18 else 'You\'re a minor'​

答案3:

def is_adult(age):
    return "You\'re an adult" if age >=18 else "You\'re a minor"​

答案4:

def is_adult(age):
    if age>=18:
        return "You\'re an adult"
    elif age<18 and age>=0:
        return "You're a minor"​

答案5:

def is_adult(age):
    return ['You\'re an adult','You\'re a minor'][age < 18]​

答案6:

def is_adult(age):
    return f"You're a{['n adult', ' minor'][age < 18]}"​

答案7:

def is_adult(age):
    return ["You're a minor","You're an adult"][age > 17]​

答案8:

def is_adult(age):
    old = None
    if age >= 18:
        old = 'an adult'
    else:
        old = 'a minor'
    return 'You\'re ' + old​

答案9:

def is_adult(age):
    return 'You\'re a'+(' minor' if age<18 else 'n adult')
​
上一篇:C++ 获取系统版本号


下一篇:Codewars-python每日练习(3)