我的函数是否针对此问题正常工作? (MIT OCW-Comp Sci教科书简介-Python手指练习)

问题描述 投票:0回答:1

我满足这些要求吗?

((MIT OCW Comp Sci教科书简介-手指锻炼)

编写一个程序,要求用户输入整数并打印两个整数,分别是root和pwr,这样0

我的答案

one_user_input = float(raw_input("Enter a number: "))


def check_nth_root(x):
    for nth_root in range(1, 6):
        nth_root = float(nth_root)

        calculation = one_user_input ** (1.0 / nth_root)

        x = one_user_input % calculation
        x = round(x, 9)
        if x % nth_root == 0:
            print "Root {} & Power {}".format(calculation, nth_root)

        else:
            print "Root and power pair, doesn't exist"


check_nth_root(one_user_input)

python math
1个回答
0
投票

如果答案是在python3中,则在使用print()时需要带括号。

© www.soinside.com 2019 - 2024. All rights reserved.