繁体   English   中英

我不知道如何根据我插入的指数更改此处的“正方形”。 如果是 3,我想打印“立方体”等等。 你能帮帮伙计们吗? 谢谢

[英]I don't know how I can change the "square" here based on the exponent I insert. If it's 3 I want to print "cube" and so on. Could you help guys. Thx

def generator(base1, exponent1):
    u = base1 ** exponent1
    return u

base = int(input("Enter the base number: "))
exponent = int(input("Enter the exponent: "))

print("The *square* of the number", base, "is", generator(base, exponent))

您实际上可以创建一个字典来存储squarecube 如果存在,则获取该值,或将其raised to... power将被格式化:

dict1={2:'squared',3:'cubed'}

print(f"The base {dict1.get(exponent) if exponent in dict1 else f'raised to {exponent}th power'}, is, {generator(base, exponent)}")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM