I'm writing a program that tells the user to input the amount of rooms that a property has, and then a while loop finds out the width and length of each room. I feel like I need the while loop to create two extra variables to store the width and length every time it iterates, however I can not figure out how. here is my code so far:
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")
Its not much, but I have been searching the internet and haven't found out how.
What I would like the program to do is to ask the user how many rooms the property has and then for each room it should ask for the width and length of the room. The program then should display the total area of the floor space in a user friendly format
updated code:
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)
However, after inputting the values of the room dimensions, it gives me a traceback error on line 15 and says currentRoomNumber2 is not defined. Where have I gone wrong?
room("For room", roomcount,", what is the length?:\n")Is this a function call because it sure looks like one. What are you trying to do here?roomcounteach time your while loops? if so just goroomcount += 1roomCountandroomcount, and I think your while expression should look likeroomcount <= rooms. Also, don't forget to incrementroomcountafter each iteration.