简体   繁体   中英

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)

Give a decimal number: 5.5

Give an integer number: 3

5.5 to the power of 3 is approximately 166.

To be exact it is 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)+".")

File " tester .python3", line 10

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

SyntaxError: invalid syntax

The format specification needs to be a string, and thus inside quotes:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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