In class we are working on functions that calculate the area of a square or rectangle. The program asks for a person's name, what shape they want and what the length and width are. It then prints the area of that shape, and the program loops back around again. What I'm looking to do is take each individual name input and area and output them into a text file. Our teacher didn't make it too clear on how to do this. Any help would be appreciated. Here's the code:
import time
def area(l, w):
area = l * w
return area
def square():
width = int(input("please enter the width of the square"))
squareArea = area(width, width)
return squareArea
def rectangle():
width = int(input("please enter the width of the rectangle"))
length = int(input("please enter the length of the rectangle"))
rectangleArea = area(length, width)
return rectangleArea
def main():
name = input("please enter your name")
shape = input("please enter s(square) or r(rectangle)")
if shape == "r" or shape =="R":
print ("area =", rectangle())
main()
elif shape == "s" or shape == "S":
print ("area =", square())
main()
else:
print ("please try again")
main()
main()
Edit: I don't think I asked the question clear enough, sorry. I want to be able to input something, e.g. the name and be able to put it into a text file.