2013-05-20 2 views
0

저는 파이썬을 처음 접했고 화씨를 섭씨로 변환하고 싶다면 파이썬 프로그램을 만들려고합니다. 여기에 프로그램입니다 :섭씨와 화씨로 변환하기

x = (raw_input("would you like to convert fahrenheit(f) or celsius(c)?")) 
if x == "f": 
y = (raw_input("what is the fahrenheit?")) 
f = (int(y) - 32) * 5.0/9 
print f 

if x == "c": 
n = (raw_input("what is the celsius?")) 
z = (int(n) *9)/5 + 32 
print "and in fahrenheit, that is:" 
print z 

나는 elif x == "c"if x == "c"을 변경했지만, 그것은 나에게 TextError했다. 어떤 아이디어?

답변

1

당신은 그 중 하나를 제거해야 할 것 :

print f 

전화를하거나, 나중에 이동하거나, 들여 쓰기는 ELIF이 경우 블록 직후에해야하기 때문에, 그리고 인쇄 문으로 들여 쓰기 그건 그렇고, 그것은 if 블록을 끝낸다. 그냥 들여 쓰기 print

3

:

x = raw_input("would you like to convert fahrenheit(f) or celsius(c)?") 
if x == "f": 
    y = raw_input("what is the fahrenheit?") 
    f = (int(y) - 32) * 5.0/9 
    print f 
elif x == "c": 
    n = raw_input("what is the celsius?") 
    z = (int(n) * 9)/5.0 + 32 
    print "and in fahrenheit, that is:" 
    print z 
1

쉬운 방법이 될 수 있습니다

x = (raw_input("would you like to convert fahrenheit(f) or celsius(c)? ")) 
if x == "f": 
    y = (raw_input("what is the fahrenheit?")) 
    f = (int(y) - 32) * 5.0/9 
    print "and in celsius, that is: ", 
    print f 
elif x == "c": 
    y = (raw_input("what is the celsius?")) 
    f = (int(y) *9)/5.0 + 32 
    print "and in fahrenheit, that is: ", 
    print f 
else 
    print "Error" 
+0

이 항상 "오류"를 인쇄합니다. 'print 'Error "'앞에'else'가 없습니다. – srikanta

+0

감사합니다. @srikanta. Ans가 업데이트되었습니다. – sinhayash

+1

else와 함께 no : 다음은 SyntaxError입니다. 최근에 루아에서 코딩 했습니까? ;) – kampu

관련 문제