def bmicalculation(self):
bmiheight=self.heightcm.get()
print(bmiheight)
bmiweight=self.weightkg.get()
bmi= float((bmiweight)/((bmiheight/100)**2))
print(bmi)
self.label1=Label(self.master,text='Your BMI is %.2f' % bmi).grid(row=5,column=0)
if bmi <= 18.5:
self.label2=Label(self.master,text='This places you in the underweight group.',fg='blue').grid(row=6,column=0)
totalindex = 'underweight'
elif bmi >18.5 and bmi <25:
self.label3=Label(self.master,text='This places you in the healthy weight group.',fg='green').grid(row=6,column=0)
totalindex = 'healthy'
elif bmi >= 25 and bmi < 30:
self.label4=Label(self.master,text='This places you in the overweight group.',fg='orange').grid(row=6,column=0)
totalindex = 'overweight'
elif bmi >=30:
self.label5=Label(self.master,text='This places you in the obese group.',fg='red').grid(row=6,column=0)
totalindex = 'obese'
if bmi >0 and bmi <999999999999999999999:
self.button6=Button(self.master,text="Store Data",fg='red',command=self.dynamic_data_entry).grid(row=8,column=0)
def dynamic_data_entry(self):
#this is what adds the data to the database. Bmi has to be changed to the value of bmi and weightclass has to be change to the weightclass
timestamp = str(datetime.datetime.now().date())
bodymassindex = '20'
weightclass = str(totalindex)
c.execute("INSERT INTO BMIStorage (timestamp, bodymassindex, weightclass) VALUES (?, ?, ?)",(timestamp, bodymassindex, weightclass))
conn.commit()
我想回顧一下我在第二個定義def dynamic_data_entry
中創建的bmi
這個術語。我怎樣才能做到這一點?參考python中的先前語句
另外,我怎麼能把BMI給出的權重組轉換成一個字符串,然後我可以把它放入由SQLite創建的數據庫中?
是凹處是否正確? 'dynamic_data_entry'是'bmicalculation'中的一個函數嗎? –
你不能引用一行代碼。正確使用變量引用 –