gpt4 book ai didi

python - 梯形的中线

转载 作者:行者123 更新时间:2023-12-01 06:28:40 24 4
gpt4 key购买 nike

我是Python新手,我正在和我的高中生一起开发计算器。我们还没有使用库,所以我们正在长时间地进行所有计算。我们使用带有 int 和输入值的用户输入数字。我们的顶部有一个菜单,下面包含所有功能。我们还没有使用 float ,但如果我们需要使用它们,我们可以,我只需要能够向他们解释为什么、何时以及如何使用 float 。所以我的学生想出了一个公式,但我们不知道问题是什么。

'''
#Variables#
things = ['Area of a Square', 'Area of a Rectangle', 'Weight of an Object','Speed of an Object','Density of an Object', 'Velocity of an Object', 'Mass of an Object','Area of a Triangle','Median of a Trapezoid', 'Quit']
'''
'''
#Function#
'''
# printMenu() displays the menu
def printMenu ():
c = 1
for i in things:
print ('%i:\t%s' % (c, i))
c = c + 1
'''
-------

So here is the problem that is kicking our butts:
'''
#Calculates Median of a Trapezoid
def medianTrap ():
base3 = input ('Enter first base: ')
base4 = input ('Enter second base: ')
medianTrap = ((int base3 + int base4/ 2))
print ('The Median of an Trapezoid is: %i' % (medianTrap))
print()

'''救命!!!

最佳答案

问题出在这一行:

medianTrap = ((int base3 + int base4/ 2))

这不是 Python 语法,int 是一个函数 a,因此你必须将参数括在括号中:

medianTrap = ((int(base3) + int(base4)/ 2))

祝同学们一切顺利!

关于python - 梯形的中线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60009340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com