作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是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/
我是一名优秀的程序员,十分优秀!