Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed I made a Area of a circle calculator for school, how do I use a while loop to ask for the radius again?

+2 votes
asked Sep 20, 2022 by Ben Roberts (230 points)
closed Sep 27, 2022 by Ben Roberts

Link to the project https://onlinegdb.com/2--AfMAmvT

closed with the note: Answered

1 Answer

0 votes
answered Sep 24, 2022 by Peter Minarik (86,040 points)

Here's an example of how to do it.

I also used math.pi to have higher accuracy and used a new variable for the area not to confuse anyone as for you, the variable rad is not containing the radius anymore, but the area in the end.

import math

print("Welcome to Area of a Circle Calculator. Please enter the Radius of the circle. Enter an invalid radius (less than 0) to quit.")
rad = float(input("r = "))
while (rad >= 0):
    area = rad *rad * math.pi
    print(f"The area of the circle is {area}.")
    rad = float(input("r = "))
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...