【发布时间】:2016-12-26 13:20:26
【问题描述】:
圣诞快乐!
我试图生成一些代码,这些代码将使用用户提供的信息创建一种数据库。
我可以使用input() 方法来定义我的实例变量吗?
class Compound:
def __init__(self, name, state, molecular_mass, concentration, concentration_measure):
self.nome = name
self.state = state
self.mol_mass = molecular_mass
self.conc = concentration
self.measure = concentration_measure
def summary(self):
return ('Your compound is {} it has a state of {} it has a molecular mass of {} g/mol and a concentration of {} and a measure of {}'
.format(self.name, self.state, self.mol_mass, self.conc, self.measure))
def ask_compounds():
self.nome = input("Name?")
self.state = input('Solid or Liquid')
self.mas_mol = input('Absolute number for molecular weight?')
self.conc = input('Concentration?')
self.measure = str(input('In M? In g/ml?'))
ask_compounds()
感谢您的帮助!
【问题讨论】:
标签: python python-3.x class variables input