0

I'm a very beginner and know only the very basic syntax. I am trying to make a circumference calculator, with the user inputting the radius. This is what I have right now, but I want to be able to have a text answer like "The circumference of this circle is ____". Right now I can only output the answer.

rad = input("Enter the radius of circle: ")
radius = float(rad)
circumference = 2 * 3.14 * radius
print(circumference)
Aviv Yaniv
  • 6,188
  • 3
  • 7
  • 22
Jay L
  • 1

2 Answers2

2

Python 3

Use f-string to format result:

rad = input("Enter the radius of circle: ")
radius = float(rad)
circumference = 2 * 3.14 * radius
print(f'The circumference of this circle is {circumference}')

Python 2

Format string:

rad = input("Enter the radius of circle: ")
radius = float(rad)
circumference = 2 * 3.14 * radius
print('The circumference of this circle is {0}'.format(circumference))

Another Option: Concatenating String Directly

Less elegant, yet still works:

rad = input("Enter the radius of circle: ")
radius = float(rad)
circumference = 2 * 3.14 * radius
print('The circumference of this circle is ' + str(circumference))
Aviv Yaniv
  • 6,188
  • 3
  • 7
  • 22
1

You can use

print(f"The circumference of this circle is {circumference}")

But also you do not want to use 3.14 for pi. You can do

import math

and then use math.pi for a more accurate number.

Yaga
  • 56
  • 2