简体   繁体   English

我的 function 有“返回”,当我打印时仍然得到“无”

[英]My function have "return" and still getting "None" when I print

# look at my code below class User: def __init__(self,name, gender, age, hight, weight, activity): self.name = name self.gender = gender self.age = age self.hight = hight self.weight = weight self.activity = activity def __repr__(self): return f'Welcome back {self.name}' def get_name(self): return self.name def get_gender(self): return self.gender def get_age(self): return self.age def get_hight(self): return self.hight def get_weight(self): return self.weight def get_activity(self): return self.activity def set_age(self, new_age): self.age = new_age def set_weight(self, new_weight): self.weight = new_weight def set_activity(self, new_activity): self.activity = new_activity def daily_calories(self): if self.gender == 'men': bmr = int(((66 + (13.8 * self.weight)) + (5 * self.hight)) - (6.8 * self.age)) elif self.gender == 'women': bmr = int(((655 + (9.6 * self.weight)) + (1.8 * self.hight)) - (4.7 * self.age)) if int(self.activity) == 0: calories_out = int((1.2 * bmr) * 1.1) return print(f'\nHellow {self.name} Your body need {calories_out} calories per day') elif int(self.activity) == 1: calories_out = int((1.375 * bmr) * 1.1) return print(f'\nHellow {self.name} Your body need {calories_out} calories per day') elif int(self.activity) == 2: calories_out = int((1.55 * bmr) * 1.1) return print(f'\nHellow {self.name} Your body need {calories_out} calories per day') elif int(self.activity) == 3: calories_out = int((1.725 * bmr) * 1.1) return print(f'\nHellow {self.name} Your body need {calories_out} calories per day') else: calories_out = int((1.9 * bmr) * 1.1) return print(f'\nHellow {self.name} Your body need {calories_out} calories per day') user1 = User('User1', 'men', 41, 163, 66, 0) print(user1.daily_calories())

The print function returns None . print function 返回None You are returning that value.您正在返回该值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在函数中使用print时得到none的原因是什么,当你使用return时它解决了? - What is the reason behind getting none when I use print in the function and it is solved when you use return? 当我提前返回值为 None 时,为什么我会收到 Optional 类型的 mypy 错误? - Why am I getting a mypy error for Optional type when I have early return for when value is None? 如果每种情况都有返回值,为什么我的python函数不返回任何值? - Why does my python function return none if I have a return for every case? 如何在函数的 return print 语句末尾删除“None”? - How can I remove “None” at the end of my function's return print statement? 我从我的函数返回一个列表,但是当我打印返回的列表时,它打印 NONE - I am returning a list from my function, but when I print that returned list, it prints NONE 为什么我在 function 中的全局值在打印时返回错误? - Why is my global value in a function return an error when i print it? 当我以为我放置了一个字符串时,我的函数使我返回“ none”吗? - My function drops me in the return a “none” when I thought I placed a string? 函数返回None,即使我有return命令 - function returns None, even if I have return command 当我有返回值时,Python 不返回任何值 - Python returns none when I do have a return value Python:我的程序可以打印,但是返回None? - Python: My program could print, but return None?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM