讲解python、代作偶数分解两素数的python
- 首页 >> Python编程实验3:大于等于4的偶数可以写成两个素数的和的实验实验内容:使用函数和循环编写程序实验目的:掌握函数的定义 掌握range的用法 掌握循环的用法 掌握奇偶数的判断方法In 1742, a German amateur mathematician named Christian Goldbach wrote to Leonhard Euler with the following conjecture: Every number greater than 2 can be written as the sum of three prime numbers. In his conjecture, Goldbach was considering 1 as a prime number. By convention we no longer consider 1 as a prime number. And Euler later modified the conjecture as follows: Every even number greater than or equal to 4 can be expressed as the sum of two prime numbers. (每个大于等于4的偶数可以表达成两个素数的和)For example: (如)?8 = 3 + 5 ?20 = 3 + 17 = 7 + 13 ?42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23 There is no formal proof of this conjecture. However, we can verify Goldbach's conjecture in certain ranges. For this programming assignment you are asked to verify Goldbach's conjecture in a user defined range. You will prompt the user to enter the range and then your program will print out all the even numbers in that range (inclusive of the end points) in the form n = a + b, where a and b are prime numbers and a <= b. Each even number should be on a separate line followed by all possible unique pairs of prime numbers. Your sample output should look like this: (在程序中,你提示用户输入一个范围,然后你的程序输出所有的在这个范围内(包括下限)偶数以n=a+b的形式,这里a和b是素数,且a<=b.每个偶数应该在单独的一行,后面是所有可能的素数对。你的程序输出应该如下所示。)Enter the lower limit: 4Enter the upper limit: 1004 = 2 + 26 = 3 + 38 = 3 + 510 = 3 + 7 = 5 + 5........100 = ....You will do the following error checking on the input: (程序中做如下检测)?Lower limit is equal to or greater than 4 (下限大于或等于4)?Both lower limit and upper limit are even (上限和下限都是偶数)?Lower limit is strictly less than upper limit (下限必须的小于上限)Even if only one of these conditions fails, prompt the user to enter both the limits repeatedly. (如果其中一个条件没有达到,提示用户重复的输入上下限)Your program should have a good, clean logical structure. You must define the function is_prime() .(程序中定义一个函数,关断数字是否为素数)提示:1,先写一个函数is_prime,判断输入的参数是否为素数2.循环判断用户输入的参数是否满足要求?3.判断上下限中的偶数可以写成8 = 3 + 5