繁体   English   中英

要求两个数字的程序:一个小数(浮点数)和一个 integer(整数),第一个数字(浮点数)到第二个数(整数)的幂

[英]program which asks for two numbers: One decimal (floating point) and one integer (whole number), first number (float) to the power of the second (int)

给出一个十进制数:5.5

给一个 integer 编号:3

5.5 的 3 次方约为 166。

准确地说是166.38。

dec = float(input('Give a decimal number: '))
ger = input('Give an integer number: ')
z = dec**ger
print(dec,'to the power of',int,'is approximately',{0:.2f}.format(z))
print('To be exact it is',str(z)+".")

文件“ tester .python3”,第 10 行

print(dec,'的幂',int,'大约是',{0:.2f}.format(z))

SyntaxError:无效的语法

格式规范需要是一个字符串,因此在引号内:

print(dec,'to the power of',int,'is approximately',"{0:.2f}".format(z))

暂无
暂无

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

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