私はプロパティを持つ部屋の量を入力するようにユーザーに指示し、whileループは各部屋の幅と長さを調べるプログラムを書いています。私はwhileループを必要としているので、反復するたびに幅と長さを格納するために2つの余分な変数を作成する必要があるように感じます。whileループを使用してループするたびに変数を追加するにはどうすればよいですか?
roomCount = 1
print("Please answer the questions to find the floor size.")
rooms = int(input("How many rooms has the property got?:\n"))
while roomcount >= rooms:
print("For room", roomcount,", what is the length?:\n")
そのあまりありませんが、私はインターネットを検索していると方法を発見していない:ここ は、これまでの私のコードです。
私はこのプログラムに何をしたいのですか?どのくらい多くの部屋に物件があるのかを尋ねると、各部屋ごとに部屋の幅と長さを尋ねるべきです。プログラムは、ユーザーフレンドリーなフォーマット
更新されたコードで床面積の合計面積を表示する必要があります。
currentRoomNumber = 0
currentRoomNumber2 = 0
floorspace = 0
whileLoop = 0
print("Please answer the questions to find the floor size.")
numberOfRooms = int(input("How many rooms has the property got?: "))
roomWidths= list()
roomLengths = list()
while currentRoomNumber < numberOfRooms:
roomWidths.append(int(input("For room " + str(currentRoomNumber + 1) + ", what is the width?: ")))
roomLengths.append(int(input("For room " + str(currentRoomNumber + 1) + ", what is the length?: ")))
currentRoomNumber += 1
while whileLoop < numberOfRooms:
floorspace += (roomLengths[(currentRoomNumer2)] * roomWidths[(currentRoomNumber2)])
currentRoomNumber2 += 1
whileLoop += 1
print(floorspace)
しかし、部屋の大きさの値を入力した後、それは私のライン上のトレースバックエラーが発生します15 currentRoomNumber2
は定義されていません。どこが間違っていたのですか?あなたは長さと幅は、部屋番号で保存したい考え
部屋番号(部屋番号、部屋数、長さは?:\ n ")' これは関数呼び出しのようです。ここで何をしようとしていますか? – MooingRawr
私の脳は正しく機能していません、申し訳ありません。それは印刷することを意味する – Student
あなたはあなたのwhileループのたびに 'roomcount'を増やそうとしていますか?もしも 'roomcount + = 1'に行くだけです。 – MooingRawr