Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python中带有类的if语句_Python 3.x_Oop_If Statement - Fatal编程技术网

Python 3.x Python中带有类的if语句

Python 3.x Python中带有类的if语句,python-3.x,oop,if-statement,Python 3.x,Oop,If Statement,我正在制作一个小的命令提示符菜单程序。用户选择一个字母选项,代码将它们带到一个小的代码集,该代码为它们进行特定的计算 我已经把菜单准备好了。但是,当我为分销商运行C时,不会打印任何内容。我应该换什么 def main(): variable_to_cause_loop = "Y" while variable_to_cause_loop == "Y": print ('A: Accounting') print ('B: Quick Est

我正在制作一个小的命令提示符菜单程序。用户选择一个字母选项,代码将它们带到一个小的代码集,该代码为它们进行特定的计算

我已经把菜单准备好了。但是,当我为分销商运行
C
时,不会打印任何内容。我应该换什么

def main():

    variable_to_cause_loop = "Y"

    while  variable_to_cause_loop == "Y":

        print ('A: Accounting')
        print ('B: Quick Estimate')
        print ('C: Distributors')

        User_Menu_Selection = input('Enter an option: ')

        if User_Menu_Selection == "A":
            print("Feature not available")


        elif User_Menu_Selection == "B":


            class Shoes:
                print('COMPANY MESSAGE', '\n' *5)
                print('--> Quick Estimates <--')

                def __init__(self, Model, Descpstr, price):
                    self.Model = Model
                    self.Descpstr = Descpstr
                    self.price = int(price)



            A100 = Shoes("A100", "Prada Flat Black", 100)
            A200= Shoes("A300", "Gucci Heel Black", 275)



            product_num = input('> Shoe Model(model number): ')
            product_size = input('> Shoe Size: ')
            product_qty = input('> Quantitiy: ')
            ship_zip_code = input('> Ship to Zip Code: ')




            if product_num == "A100" or product_num == "a100":
                order_calc = float(A100.price) * float(product_qty)
                print (float(order_calc))

            elif product_num == "A200" or product_num == "a200":
                order_calc = float(A200.price) * float(product_qty)
                print (float(order_calc))


            elif User_Menu_Selection == "C":
                print ("")
                print ("DISTRIBUTORS")
                print ("")
                print ("")
                print ("> Elderado's   Rep: Jack Reed   - Phone  # 1-888-562-2229 <")
                print ("> Friendly's   Rep: Roy Jack Jones   - Phone # 1-212-393-9939 <")
                print ("> Best Shoes Fort Wayne  Rep: Price Gouger   - Phone # 1-331-3832 <")
                print ("> The Rubber Maker   Rep: Crumble Crustipher   - Phone # 1-434-1919 <")




    variable_to_cause_loop = input ("For Main Menu Type Y" )

main()
def main():
变量\u to \u cause\u loop=“Y”
变量_to_导致_循环==“Y”:
打印(‘A:会计’)
打印('B:快速估算')
打印('C:分销商')
用户菜单选择=输入('输入选项:')
如果用户菜单选择==“A”:
打印(“功能不可用”)
elif用户菜单选择==“B”:
职业鞋:
打印('公司消息','\n'*5)
打印('-->快速估算鞋款(型号):')
产品尺寸=输入(“>鞋尺寸:”)
产品数量=输入('>数量:')
ship_zip_code=输入('>ship to zip code:'))
如果产品数量=“A100”或产品数量=“A100”:
订单计算=浮动(A100.价格)*浮动(产品数量)
打印(浮动(订单计算))
elif product_num==“A200”或product_num==“A200”:
订单计算=浮动(200.价格)*浮动(产品数量)
打印(浮动(订单计算))
elif用户菜单选择==“C”:
打印(“”)
印刷品(“分销商”)
打印(“”)
打印(“”)

打印(“>Elderado的代表:杰克·里德-电话#1-888-562-2229友好的代表:罗伊·杰克·琼斯-电话#1-212-393-9939韦恩堡最佳鞋代表:普赖斯·高格-电话#1-331-3832橡胶制造商代表:克拉姆·卡普里弗-电话#1-434-1919,如@craig meier的评论中所述,取消elif用户菜单的选择=”C:
因此它与“A”和“B”语句一致


此外,您使用的是
input
,因此您必须键入带引号的
“A”
。您很可能希望使用
raw\u input
,这样您就可以键入
A
,而不带引号。

如@craig meier的评论中所述,取消
elif用户菜单的选择==“C”:
,因此它与“A”和“A”保持一致B“声明”


此外,您使用的是
输入
,因此您必须键入带引号的
“A”
。您很可能希望使用
原始输入
,这样您就可以只键入
A
,而不带引号。

缩进与问题中显示的缩进完全相同(即,用elif表示“C”)“是
product_num
ifs的对等项,而不是另一个
User_菜单选择
ifs),或者这只是粘贴时的格式错误?您的缩进是否与问题中显示的完全相同(即,使用“C”的elif是
product_num
ifs的对等项,而不是另一个
User_菜单选择
ifs)或者这仅仅是粘贴时的格式错误?
input
vs
raw\u input
这件事只适用于Python2.x。在Python3中,原始的
input
被删除,
raw\u input
被重命名为
input
。我错过了指定python版本的问题标签。谢谢您的更正@CraigMeier根据您的经验,原始输入的优势是什么?@CoolJack1001
raw\u input
在Python2.x中做的是
input
在Python3.x中做的(即您想要的)。在Python2.x中,
input(…)
做了Python3.x将做的
eval(input(…)
(这很少是个好主意——只要问问小Bobby Tables,当您执行未初始化的输入时会发生什么)
input
vs
raw\u input
只适用于Python2.x。在Python3中,原始的
input
被删除,
raw\u input
被重命名为
input
。我错过了指定python版本的问题标签。感谢您的更正。@CraigMeier根据您的经验,它的优势是什么在Python2.x中,@CoolJack1001
raw\u input
做了Python3.x中的
input
做了Python3.x中的
input(…)
做了Python3.x所做的
eval(input(…)
(这很少是个好主意——只要问问小Bobby表,当执行未初始化的输入时会发生什么)。