[Python] Can't find why my code isn't exiting the loop and printing

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I'm attempting to write code in python that will calculate the area and circumference from the radius. Whenever I run the code it just returns "Please enter a radius for calculation." Like it never breaks the loop and starts back from the while true.

    import math

    radius = input()
    #Area
    x = math.pi*radius**2
    #Circumference
    y = 2*math.pi*radius**2

    while True:
    print('Enter a radius for calculation: ')
    try:
    radius = int(radius)
    except:
    print('Please use numeric digit.')
    continue
    if radius < 1:
    print('Please enter a positive number.')
    continue
    break
    print ('The area is', x)
    print ('The circumference is', y)


    I'm expecting the output of the area and circumference. From what I can tell the break should end the loop and immediately run the print statements. But, it immediately returns to the while true I'm just at a loss for words.

    Continue reading...

Compartilhe esta Página