나는 속성이있는 방의 양을 입력하라는 프로그램을 작성하고 while 루프는 각 방의 너비와 길이를 알아 낸다. 반복 할 때마다 너비와 길이를 저장하기 위해 두 개의 추가 변수를 만드는 while 루프가 필요하다고 생각합니다. 그러나 방법을 파악할 수는 없습니다. 여기에 지금까지 내 코드입니다 :루프가 반복 될 때마다 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
은 정의되지 않았습니다. 내가 어디로 잘못 갔니?
':
출력은/스크립트의 실행 사항은 다음과 같이 될 것이다 방 ("room", roomcount, "길이는 무엇입니까? : \ n")' 확실히 하나이기 때문에이 함수 호출입니다. 너 여기서 뭘하려고하는거야? – MooingRawr
내 뇌가 제대로 작동하지 않습니다. 죄송합니다. 그것의 인쇄물을 말하려고합니다 – Student
while 루프 때마다 'roomcount'를 늘리려고합니까? 만약 그냥 'roomcount + = 1'이 보일 경우 – MooingRawr