クラスでは、正方形または長方形の面積を計算する関数を扱っています。プログラムは、人の名前、彼らが望む形状、長さと幅が何かを求めます。その後、その形状の領域を印刷し、プログラムは再びループバックします。私がしようとしているのは、それぞれの個々の名前の入力と領域を取り、それらをテキストファイルに出力することです。私たちの先生は、これを行う方法についてあまりにも明確にしていませんでした。どんな助けもありがとう。コードは次のとおりです:私はこれらの入力をテキストファイルに入れようとしています
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()
編集:私は十分に質問をしたとは思わない、申し訳ありません。私は何かを入力できるようにしたい。それをテキストファイルに入れることができます。
あなたが入力を取得したい* *からテキストファイル、または出力*をテキストファイルに送信したいのですか? – Barmar
出力をテキストファイルに送信 –