带Python类的if语句

时间:2019-02-21 00:44:10

标签: python-3.x oop if-statement

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

我已经可以使用菜单了。但是,当我为分销商运行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() 时,没有任何显示。我应该改变什么?

<div id="mySidebar" class="sidebar">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
  <a href="/">Home</a>
  <a href="/accounts/login">Login</a>
  <a href="#">Profile</a>
  <a href="/upload">Upload</a>
  <a href="/top_photos">Top Photos</a>
  <a href="/aboutus">About Us</a>
  <a href="/contact">Contact Us</a>
</div>

1 个答案:

答案 0 :(得分:0)

如@ craig-meier的评论中所述,请取消缩进elif User_Menu_Selection == "C":,使其与“ A”和“ B”语句一致。

此外,您正在使用input,因此必须用引号输入"A"。您很可能希望使用raw_input来代替,因此您只需键入A而不带引号即可。