Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何求对数值之和_Python_Logarithm_Natural Logarithm - Fatal编程技术网

Python 如何求对数值之和

Python 如何求对数值之和,python,logarithm,natural-logarithm,Python,Logarithm,Natural Logarithm,我刚开始学习Python 3,我有以下问题需要解决: 编写一个程序,计算从1到某个数n的所有素数的对数之和,并打印出素数的对数之和 a、 输入:整数n b、 输出:日志(1)、日志(2)、日志(3)、日志(n)(日志的基数为10)之和“数学模块中有一个log10函数,因此您无需自己计算日志。所以你可以这样做: import math def is_prime(x): # Write a function that returns whether x is prime def log_

我刚开始学习Python 3,我有以下问题需要解决:

编写一个程序,计算从1到某个数n的所有素数的对数之和,并打印出素数的对数之和

a、 输入:整数n


b、 输出:日志(1)、日志(2)、日志(3)、日志(n)(日志的基数为10)之和“

数学模块中有一个
log10
函数,因此您无需自己计算日志。所以你可以这样做:

import math

def is_prime(x):
    # Write a function that returns whether x is prime

def log_sum(n):
    # Return the sum of all logs for primes smaller than n
    log_total = 0
    for i in range(1, n+1):
        if is_prime(i):
            log_total += math.log10(i)
    return log_total

要求家庭作业帮助的问题必须包括到目前为止你为解决问题所做工作的总结,以及对你解决问题的困难的描述。请阅读你的文章。