Python练习题答案: 摩门经【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战

摩门经【难度:2级】:

答案1:

from math import log, ceil
def mormons(starting_number, reach, target):
    return ceil( log(target/starting_number) / log(1+reach) )

答案2:

def mormons(starting_number, reach, target):
    missions = 0
    while starting_number < target:
        starting_number += starting_number * reach
        missions += 1
    return missions


# def mormons(start, reach, target, missions=0):
#     if start >= target:
#         return missions
#     return mormons(start + (start * reach), reach, target, missions + 1)​

答案3:

def mormons(start, fac, target):
    return 0 if start >= target else 1 + mormons(start * (fac + 1), fac, target)

答案4:

import math
def mormons(starting_number, reach, target):
    return math.ceil(math.log(target/starting_number,reach+1))

答案5:

from math import ceil, log

def mormons(n, r, target):
    return ceil(log(target/n, r+1))

答案6:

def mormons(n, r, target):
    c = 0
    while n < target:
        n *= r + 1
        c += 1
    return c​

答案7:

def mormons(starting_number, reach, target):
    return 0 if starting_number>=target else 1+mormons(starting_number*(1+reach), reach, target)

答案8:

def mormons(number, reach, target):
    c = 0
    while number < target:
        number += reach*number
        c += 1
    return c​

答案9:

def mormons(m, reach, target):
    t = 0
    while m < target:
        m, t = m * reach + m, t + 1
    return t​

答案10:

mormons=m=lambda s,r,t:s<t and-~m(-~r*s,r,t)



Python基础训练营景越Python基础训练营QQ群

在这里插入图片描述
欢迎各位同学加群讨论,一起学习,共同成长!

你可能感兴趣的:(Python编程进阶练习题)