2017-11-26 2 views
-2

내가 학교 프로젝트를 위해 작성된 몇 가지 코드를 왜 이해가 안하지만 내 코드은 나가서 설명하자면 NameError가 나타나고 있지만

fullname = input("whats your name?") 
print("hello",fullname,) 
print("room 1") 
width=input("how wide is the room?") 
length=input("how long is the room?") 
area = float(length)*float(width) 
print("the total area is",area,) 

q = input("do you want another room?") 
if q == "yes": 
    print("room 2 ") 
    widtha=input("how wide is the room?") 
    lengtha=input("how long is the room?") 
    areaa = float(lengtha) * float(widtha) 
    print("the total area is",areaa,".") 
else: 
    flooring=input("do you want to have wood flooring(10) or tiled flooring(15)") 
    if flooring == "wood": 
     costaa = float(area)+ float(areaa)*10 
     print("total cost is ",costaa,) 
    if flooring == "tiled": 
     costab = float(area)+ float(areaa)*15 
     print("total cost is £",costab,) 

을 비용 부품의 모든에 오류를 표시 내가 선택한 것에 따라 정의된다.

+1

areaa 변수가 else 문에 정의되어 있지 않습니다. 그것은 실행되지 않을 수있는 if 문을 정의합니다. 이해가되는지 모르겠다 –

+0

파이썬 오류 메시지는 일반적으로 오류가 발생한 행을 표시합니다. –

답변

-1

나는 코드를 테스트하고 내 PC에서 ok를 실행합니다. 어쩌면 그것은 당신의 구성 일 것입니다. 파이썬

2

input_variable = raw_input을 ("당신의 이름을 입력 :") 당신이 파이썬 3.x를를 사용하는 경우

을 raw_input을이 변경되었습니다 입력

0

당신의 문제에 대한 대답은 간단합니다. 컴퓨터가 : 다른 방을 원합니까? 그리고 당신은 아니오라고 말하면서, 당신은 areaa의 가치를 전혀 정의하지 않습니다. 그러므로 당신이 지정하지 않았기 때문에 areaa는 존재하지 않습니다. 내가 코드를 변경하여 작동하도록 만들었습니다. 도움이되기를 바랍니다!

fullname = input("Whats Your Name?") 
print("Hello", fullname) 
print("\nRoom 1") 

width = input("How wide is the room?") 
length = input("How long is the room?") 

area = float(length) * float(width) 
print("The Total Area is", area) 

q = input("\nDo you want Another Room? (y/n)") 

if q == "y": 
    print("\nRoom 2") 
    width2 = input("How wide is the room?") 
    length2 = input("How long is the room?") 
    area2 = float(length2) * float(width2) 
    print("The Total Area is", area2,".") 

    flooring=input("\nDo you want to have Wood Flooring(10) or Tiled Flooring(15)? (wood/tiled)") 
    if flooring == 'wood': 
     cost = area + area2 * 10 
     print("Total Cost is ",cost) 
    if flooring == 'tiled': 
     cost2 = area + area2 * 15 
     print("Total Cost is ",cost2) 

else: 
    flooring=input("\nDo you want to have Wood Flooring(10) or Tiled Flooring(15)? (wood/tiled)") 
    if flooring == 'wood': 
     cost = area * 10 
     print("Total Cost is ",cost) 
    if flooring == 'tiled': 
     cost2 = area * 15 
     print("Total Cost is ",cost2) 
관련 문제