0

I have been given an assignment by my teacher in class to write a Python program that calculates the circumference and area of certain shapes. So far my first bit of code

import math

print ('Circumference and Area calculator')
def loop():
    again = input ('Would you like to make any more calculations? (y/n)').lower()
    if again == "y":
        choice()
    elif again == "n":
            print ('\nGoodbye')
    else:
            print ('Please enter y for yes and n for no')
            print ('Try again')
            loop()

But when I run this module in the Python IDLE the input does not show up, and it just prints "Circumference and Area calculator". After removing def loop(): the input works, but with it it doesn't.

Would any one be able to give a solution or send me on the right path?

4
  • Did you call loop function?
    – apsdehal
    Commented Nov 8, 2017 at 23:07
  • You never invoke the function loop()
    – Abend
    Commented Nov 8, 2017 at 23:07
  • I like how this has an attempt to solve the problem, shows some level of understanding of python and requests for the right path
    – s3bw
    Commented Nov 8, 2017 at 23:18
  • 1
    Don't use recursion where a while loop would work perfectly well.
    – chepner
    Commented Nov 8, 2017 at 23:26

2 Answers 2

1

You've defined the function loop() but you never call it. You'll want something like this at the end of the file:

if __name__ == "__main__":
    loop()

Docs on what this does for Python 3 can be found here.

0

You need to call loop function Try this:

import math

print ('Circumference and Area calculator')
def loop():
    again = input ('Would you like to make any more calculations? (y/n)').lower()
    if again == "y":
        choice()
    elif again == "n":
            print ('\nGoodbye')
    else:
            print ('Please enter y for yes and n for no')
            print ('Try again')
            loop()
if __name__ == '__main__':
    loop()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.