首页 > 解决方案 > if 和 else 函数中的无效语法 | 带变量的数学方程

问题描述

我正在尝试创建一个程序,用户可以在其中输入他们所知道的关于金字塔的值并轻松获取所有值。

NA = 0
width = 20
print ('Welcome To The \"Big Bertha Of Right Rectangle Equations\"'.rjust(width,'-'))
print("Enter In All The Measurements You Have")
print("If You Don't Have A Measurement Please Enter \"NA\"")
print(" ")
BaseLength = ( input ("Enter Base Length: ") )
BaseWidth =  ( input ("Enter A Base Width: ") )
PyramidHeight = ( input ("Enter Pyramid Height: ") )
PyramidVolume = (input ("Enter Pyramid Volume: ") )

if BaseLength == NA:
    print("No Worries We\'ll Find Base Width For You!")
    BaseLengthCalc = int((PyramidVolume / (PyramidHeight * BaseWidth) * 3))

if BaseWidth == NA:
    print("No Worries We\'ll Find Base Width For You!")
    BaseWidthCalc = int((PyramidVolume/(PyramidHeight*BaseLength))*3)

if PyramidHeight == NA:
    print("No Worries We\'ll Find Pyramid Height For You!")
    PyramidHeightCalc = int((PyramidVolume/(BaseLength*BaseWidth))*3)

if PyramidVolume == NA:
    print("No Worries We\'ll Find Pyramid Volume For You!")
    PyramidVolumeCalc = int((BaseLength*BaseWidth*PyramidHeight/3))

    print("Here's All The Calculations Boss!")
    print(" ")

if BaseLength == NA:
    print(BaseLengthCalc)
else BaseLength == BaseLength:
    print("Base Length" + BaseLengthCalc)

if BaseWidth == NA:
    print(BaseWidthCalc)
else = BaseWidth == BaseWidth:
    print("Base Width" + BaseWidth)

if PyramidHeight == NA:
    print(PyramidHeight)
else :PyramidHeight == PyramidHeight:
    print("Pyramid Height" + PyramidHeight)

if PyramidVolume == NA:
    print(PyramidVolumeCalc)
else PyramidVolume == PyramidVolume:
    print("Pyramid Volume" + PyramidVolume)

else 和变量之间的预期语句,我是新手,只是渴望学习,所以请善待!谢谢!

标签: pythonif-statementvariablesmath

解决方案


if BaseLength == NA:
    print(BaseLengthCalc)\
else not BaseLength != BaseLength
    print("Base Length" + BaseLengthCalc)

后面那句话是什么else?那不是 Python 语法。也许你elif在这里需要一个和一个冒号,但这个表达式也没有意义。我也不确定您要对线路延续做什么。


推荐阅读