素数:
能被1和它本身整除的数字称为素数。(例如-->3,5,7)
1)是否找到质数:
no = int(input("Enter no. ")) div = 2 while div<no: if no print prime break div else:> <p>输出:<br> </p> <pre class="brush:php;toolbar:false">1)Enter no. 5 Prime 2)Enter no. 6 Not Prime
2) 将输入的数字反转并判断反转后的数字是否是质数:
def reverse_a_no(no): reverse = 0 while no>0: rem = no%10 reverse = (reverse*10) + rem no//=10 #no=no//10 return reverse no = int(input("Enter no. ")) reversed_no = reverse_a_no(no) #31 71 print(reversed_no) def find_prime(no): div = 2 while div<no: if no return false break div else: true result1="find_prime(no)" result2="find_prime(reversed_no)" result2: print number emirp> <p>输出:<br> </p> <pre class="brush:php;toolbar:false">1)Enter no. 15 51 EMIRP number 2)Enter no. 14 41 not EMIRP number
完美数字
完美数意味着它的可整除数之和将等于该数。(例如-->6 能被 1,2,3 整除并且 1 2 3=6)
def find_perfect(no): total = 0 div = 1 while div<no: if no total="total" div else: no: return true false no. result="find_perfect(no)" true: print number perfect> <p>输出:<br> </p> <pre class="brush:php;toolbar:false">Enter no. 6 Perfect Number
平方根:
求输入数字的平方以及该平方根数的数字之和。
def square(no): return no**2 no=int(input("Enter the number:")) result=square(no) def sum_of_digits(num): sum=0 while num>0: sum=sum+num%10 num=num//10 return sum if result <p>输出:<br> </p> <pre class="brush:php;toolbar:false">Enter the number:4 7
在上面的示例中,给定的输入数字是 4,
-->4 的平方根是 4x4=16
-->该平方数 1 6=7 的各位数字之和。
任务-1 **
**自守数
检查一个数字的平方是否以相同的数字结尾。
示例:5 → 自同构 (5²=25)、6 → 自同构 (6²=36)、7 → 非自同构。
def square(no): return no**2 no=int(input("Enter the number:")) result=square(no) print(result) while result>0: rem=result%10 if rem==no: print("Automorphic number") break else: print("Not Automorphic number") break
输出:
1)Enter the number:5 25 Automorphic number 2)Enter the number:4 16 Not Automorphic number
任务:2
斐波那契数列
生成达到给定数字的斐波那契数列。
示例:输入:10 → 输出:0, 1, 1, 2, 3, 5, 8.
no = int(input("Enter the number of required sequence: ")) first_num,sec_num =0 ,1 while first_num <p>输出:<br> </p> <pre class="brush:php;toolbar:false">Enter the number of required sequence: 10 0 1 1 2 3 5 8
以上是Python Day-循环-练习和任务的详细内容。更多信息请关注PHP中文网其他相关文章!

Python列表切片的基本语法是list[start:stop:step]。1.start是包含的第一个元素索引,2.stop是排除的第一个元素索引,3.step决定元素之间的步长。切片不仅用于提取数据,还可以修改和反转列表。

ListSoutPerformarRaysin:1)DynamicsizicsizingandFrequentInsertions/删除,2)储存的二聚体和3)MemoryFeliceFiceForceforseforsparsedata,butmayhaveslightperformancecostsinclentoperations。

toConvertapythonarraytoalist,usEthelist()constructororageneratorexpression.1)intimpthearraymoduleandcreateanArray.2)USELIST(ARR)或[XFORXINARR] to ConconverTittoalist,请考虑performorefformanceandmemoryfformanceandmemoryfformienceforlargedAtasetset。

choosearraysoverlistsinpythonforbetterperformanceandmemoryfliceSpecificScenarios.1)largenumericaldatasets:arraysreducememoryusage.2)绩效 - 临界杂货:arraysoffersoffersOffersOffersOffersPoostSfoostSforsssfortasssfortaskslikeappensearch orearch.3)testessenforcety:arraysenforce:arraysenforc

在Python中,可以使用for循环、enumerate和列表推导式遍历列表;在Java中,可以使用传统for循环和增强for循环遍历数组。1.Python列表遍历方法包括:for循环、enumerate和列表推导式。2.Java数组遍历方法包括:传统for循环和增强for循环。

本文讨论了Python版本3.10中介绍的新“匹配”语句,该语句与其他语言相同。它增强了代码的可读性,并为传统的if-elif-el提供了性能优势

Python中的功能注释将元数据添加到函数中,以进行类型检查,文档和IDE支持。它们增强了代码的可读性,维护,并且在API开发,数据科学和图书馆创建中至关重要。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3汉化版
中文版,非常好用

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。