2013-06-05 2 views
20

우리의 지오메트리 선생님은 실제 생활에서 토이가 지오 메트릭을 사용할 때의 예를 만들기 위해 우리에게 과제를주었습니다. 그래서 수영장을 채우는 데 필요한 물의 양을 계산하는 프로그램을 만드는 것이 멋지다고 생각했습니다. 특정 모양 및 특정 치수.'str'및 'float'객체를 연결할 수 없습니까?

import easygui 
easygui.msgbox("This program will help determine how many gallons will be needed to fill up a pool based off of the dimensions given.") 
pool=easygui.buttonbox("What is the shape of the pool?", 
       choices=['square/rectangle','circle']) 
if pool=='circle': 
height=easygui.enterbox("How deep is the pool?") 
radius=easygui.enterbox("What is the distance between the edge of the pool and the center of the pool (radius)?") 
easygui.msgbox=("You need "+(3.14*(float(radius)**2) * float(height)) + "gallons of water to fill this pool.") 

그래도 난이 오류가 계속 : easygui.msgbox는 = (+ (3.14 * (플로트 (반경 "당신은 필요") ** 2) * 플로트 (여기

지금까지 프로그램입니다 높이)) + "이 풀을 채울 물의 양" TypeError : 'str'및 'float'객체를 연결할 수 없습니다.

어떻게해야합니까? 바로 인터프리터에서

easygui.msgbox=("You need "+ str(3.14*(float(radius)**2) * float(height)) + "gallons of water to fill this pool.") 

(곱셈 결과에 대한 str 캐스트 통지) :

답변

31

모든 수레 또는 비 문자열 데이터 유형이 제대로 작동합니다

연결하기 전에 문자열로 캐스트해야

>>> radius = 10 
>>> height = 10 
>>> msg = ("You need "+ str(3.14*(float(radius)**2) * float(height)) + "gallons of water to fill this pool.") 
>>> print msg 
You need 3140.0gallons of water to fill this pool. 
관련 문제