如何打印函数数学结果?[python函数](已编辑) [英] How do I print the results of my math of my functions? [python functions] (edited)

查看:49
本文介绍了如何打印函数数学结果?[python函数](已编辑)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个不同的小程序,我不知道如何显示它们,我已经完成了数学和其他工作,除了要我拼命的帮助之外,我真的不知道该说些什么,因为我不需要我一生中有在这方面有经验的人,可以为我提供帮助.

I have 3 different small programs that I have no idea how to display them, I've done the math and stuff, I don't really know what else to say, other than I need desperate help because I don't have anyone in my life that's experienced in this subject and that can help me.

  1. 此函数使用一种功能来确定是否有任何年份是a年.使您的函数返回布尔值.(Le年可被4整除,除非它们发生在新世纪初不能被400整除的年份.1900年不是a年; 2000年不是a年.)
  2. 一个程序,该程序接受一条线上的两个点,并在等式y = m x + b中返回m和b的值.(m =(y1-y2)/(x1-x2)和b = y1-m x1)
  3. 一种在子程序中使用欧几里得算法的程序,以找到两个数字的最大公因数.示例:45和55的GCF为5,顺序为:55、45、10、5、0.返回GCF

编码为1.

def isLeapYear(year):
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return True
            else:
                return False
        else:
            return True
    else:
        return False

编码为2.

    rise = y2-y1
    run = x2-x1
    m = rise/run
    b = y2/(m*x2)
    return print("m = " + str(m) + " and b = " + str(b))

编码为3.

def gcf(n1,n2):

    remainder = None

    while remainder != 0:
        remainder = n1 % n2
        n1 = n2
        n2 = remainder


    return n1

对不起,我不好解释,例如,我希望the年的功能类似;输入leap年!"(存储功能)抱歉,但是(leapyeartheyented)不是a年!(或)(他们输入的跨年)是a年!

sorry im bad at explaining things, like for example, i would want the leapyear one to function like; "Enter your leap year!" (stores function) sorry, but (leapyeartheyentered) is not a leap year! (or) (leapyear they entered) is a leap year!

是的,有人说了这句话是因为我也英语不好,我想打印编码的结果

yes someone phrased it because i'm bad at english too i suppose- i want to print the results of the coding

推荐答案

对于第一个问题,请使用:

For the first question use:

y = int(input('Enter year: '))
if isLeapYear(y):
  print('%d is a leap year' % y)
else:
  print('%d is not a leap year' % y)

第二个问题:

return print("m = " + str(m) + " and b = " + str(b))

返回 None .这是因为函数 print 返回 None .用于打印.

returns None. That's because the function print returns None. It's used for printing.

您可能想要创建一个返回某些内容的函数,或者想要打印一些内容.

You probably either wanted to create a function that returns something, or you wanted to print something.

如果您需要从函数中返回两件事,请执行以下操作:

If you need to return two things from a function you do:

return m,b

然后在调用该函数的代码中:

And then in the code that called that function:

m,b = CalcMB(x1,y1,x2,y2)

这篇关于如何打印函数数学结果?[python函数](已编辑)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆