如何从课程中获取数据

时间:2019-05-06 12:31:45

标签: python class

class Beers:

    def __init__(beer, name):
        beer.name = name

    def beer_data(beer, type, price, size, packs):
        beer.type = type
        beer.price = price
        beer.size = size
        beer.packs = packs

    def beer_additional_data(beer):
        beer.data_List = []
        beer.data_List += beer.name, beer.size*beer.packs

hjnakken = Beers('Hjnakken')
bidwsr = Beers('Bidwsr')
cirona = Beers('Cirona')

hjnakken.beer_data('Pale lager', 2.3, 6, 12)
bidwsr.beer_data('American lager', 2.0, 8, 10)
cirona.beer_data('Pale lager', 2.6, 8, 6)

hjnakken.beer_additional_data()
bidwsr.beer_additional_data()
cirona.beer_additional_data()

which_beer = input('Enter beer name: ')

在没有if语句的情况下如何执行此操作(如下)? pythonic的方式是什么?

print(which_beer.data_List)

我想在用户输入后得到XYZ.data_List

  1. 找到输入是否有效(与beer.name匹配)
  2. 打印或进一步使用XYZ.data_List

0 个答案:

没有答案