2016-12-08 2 views
0

다른 프로그램에서 함수를 가져 오는 간단한 프로그램을 작성하고 있습니다. 그것은 기본적으로 화씨를 섭씨로 전환 시키거나 그 반대로, 당신이 어떤 종류의 의견을 주는지에 따라 다릅니다. 여기에 메인 프로그램의 코드이다 : 나는 그것을 할 갈 때누락되었습니다 1 temp에 대한 필요한 위치 인수

def fahrenheit(temp): 
    fahrenheit = temp * 1.8 + 32 
    print('Your temperature in fahrenheit is ', fahrenheit) 
def celsius(temp): 
    celcius = temp - 32 
    celsius = celcius/1.8 
    print('Your temperature in celsius is ', celsius) 

, 그것은 온도 I 할게요 :

def main(): 
    temp = int(input('What is the temperature? ')) 
    print('Is this temperature in fahrenheit or celsius?') 
    system = int(input('Please put 1 for Fahrenheit and 2 for Celsius: ')) 
    if system == 1: 
     from tempconvert import celsius 
     celsius() 
    elif system == 2: 
     from tempconvert import fahrenheit 
    fahrenheit() 
    else: 
     print('I dont understand.') 
main() 

가 그리고 여기에 기능을 가져 오는 프로그램의 코드의가에서오고있다 화씨와 섭씨의 구별을 받아 들일 것입니다. 그렇다면 다음과 같이 말할 것입니다 :

celsius() missing 1 required positional argument: 'temp' 

저는 정말 이것을 이해할 수 없으므로 도움이 될 것입니다. 감사.

+0

를 주'에서()'이 모두'화씨()를 호출'과 :

celcius(32) 

당신은 당신의 프로그램의 경우 0

을 얻을 것입니다 당신이 할 것 : 시도 celsius()'를 호출합니다. 이 인수는 두 기능 모두에 필요합니다. – elethan

답변

1

귀하의 celsius에 매개 변수를 전달하는 것을 잊었다 및 fahrenheit 기능. 다음과 같이 main() 기능을 업데이트 :

def main(): 
    temp = int(input('What is the temperature? ')) 
    print('Is this temperature in fahrenheit or celsius?') 
    system = int(input('Please put 1 for Fahrenheit and 2 for Celsius: ')) 
    if system == 1: 
     from tempconvert import celsius 
     celsius(temp)  # pass 'temp' as parameter 
    elif system == 2: 
     from tempconvert import fahrenheit 
     fahrenheit(temp) # pass 'temp' as parameter 
    else: 
     print('I dont understand.') 
+0

고마워, 그것을 추가 한대로 바로 작동 :) –

1

main()에서 당신은 temp 인수없이 모두 fahrenheit()celsius() 전화,하지만 당신은 위치 인수 temp을 필요로 이러한 기능을 정의합니다.

업데이트합니다 main() 기능을 다음과 같이 (또한, 조건부 가져 오기를 수행 할 필요가 없습니다, 그냥 파일의 맨 위에 두 기능을 가져 오기) :

from tempconvert import fahrenheit, celsius 


def main(): 
    temp = int(input('What is the temperature? ')) 
    print('Is this temperature in fahrenheit or celsius?') 
    system = int(input('Please put 1 for Fahrenheit and 2 for Celsius: ')) 
    if system == 1: 
     celsius(temp) 
    elif system == 2: 
     fahrenheit(temp) 
    else: 
     print('I dont understand.') 
0

당신의 실수가 온도에 인수를 입력하지 않습니다. `

celcius(temp) 
관련 문제