我们的几何老师给了我们一个任务,要求我们创建一个玩具在现实生活中使用几何体的例子,所以我认为制作一个程序来计算需要多少加仑的水来填充某个池才是很酷的.形状,并具有一定的尺寸.
这是迄今为止的计划:
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.")
Run Code Online (Sandbox Code Playgroud)
我不断得到这个错误:easygui.msgbox =("你需要"+(3.14*(浮动(半径)**2)*浮动(高度))+"加仑水来填充这个池.")TypeError:不能连接'str'和'float'对象
我该怎么办?
我正在创建一个基本程序,它将使用GUI来获取商品的价格,如果初始价格低于10,则从价格中扣除10%,或者如果初始价格是,则从价格中取20%的折扣大于十:
import easygui
price=easygui.enterbox("What is the price of the item?")
if float(price) < 10:
easygui.msgbox("Your new price is: $"(float(price) * 0.1))
elif float(price) > 10:
easygui.msgbox("Your new price is: $"(float(price) * 0.2))
Run Code Online (Sandbox Code Playgroud)
我不断收到此错误:
easygui.msgbox("Your new price is: $"(float(price) * 0.1))
TypeError: 'str' object is not callable`
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?