Reputation: 17
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?
Upvotes: 0
Views: 3728
Reputation: 120
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.
Upvotes: 1
Reputation: 845
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()
Upvotes: 0