【问题标题】:How do i print out number variables in python 3? [closed]如何在 python 3 中打印出数字变量? [关闭]
【发布时间】:2020-05-17 14:21:21
【问题描述】:

让我先说我对编码很陌生。 我将在这里粘贴我的代码,我只想知道它有什么问题。它旨在成为 BMI 计算器。

    import math

    print('input your height and weight to find BMI.')

    num_a = int(input("feet=="))
    num_b = int(input("inches=="))
    num_c = int(input("weight(lbs)=="))

    def weight():
        int(num_c) * 2.2 

    def height():
        (int(num_a)) * 12 + int(num_b)

    def height_meters():
        (int(height)) * 0.0254

    def height_meters_sq():
        math.sqrt(int(height_meters))

    def bmi():
        (int(weight)) / int(height_meters_sq)

    print("Your BMI is..")
    print(bmi)        

每当最后的打印功能运行时,弹出的都是

函数 bmi 位于 0x7f2971a3e268

感谢任何帮助/批评,因为我仍在努力学习。

【问题讨论】:

  • 很抱歉,您到底要问什么?这里有很多要解决的问题,不幸的是,StackOverflow 不是一个教程服务,而是用于询问/回答特定编码问题。对于这些开放式问题,您可以考虑使用 reddit 之类的方法
  • 你似乎错过了一些 Python 的基础知识。我建议您为此在线阅读众多教程之一。这个网站是回答关于代码问题的问题,而不是教它
  • 注意:您输入的重量(磅)乘以 2.2,这是错误的。
  • 嗨@glitched,欢迎来到该网站。没有必要在问题中编辑说明您的问题已解决的注释,也没有必要为此编写答案。如果有帮助您解决问题的答案,请随意投票并将其标记为已接受,以表示您的赞赏和问题已解决。考虑使用tour 并阅读How to Ask

标签: python python-3.x


【解决方案1】:

这里的主要问题是您正在调用函数,因为它们是变量

这是您正确调用函数的代码:

import math

print('input your height and weight to find BMI.')

num_a = int(input("feet=="))
num_b = int(input("inches=="))
num_c = int(input("weight(lbs)=="))

def weight():
    return int(num_c) * 2.2

def height():
    return (int(num_a)) * 12 + int(num_b)

def height_meters():
    return (int(height())) * 0.0254

def height_meters_sq():
    return math.sqrt(int(height_meters()))

def bmi():
    return (int(weight())) / int(height_meters_sq())

print("Your BMI is..")
print(bmi())

结果:

input your height and weight to find BMI.
feet==10
inches==5
weight(lbs)==10
Your BMI is..
22.0

您的代码中的另一个问题是您的函数没有返回值。在python中,函数的默认返回值是None(null),所以如果你不返回值,当你打印bmi()时,它只会打印None

【讨论】:

    猜你喜欢
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2016-09-18
    • 2013-09-27
    相关资源
    最近更新 更多