## A collection of exercises for Python beginners(Q19.Autoconservative number)

A collection of exercises for Python beginners(Q19)

As a Python beginner, I’ve done a lot of practice. Most of these exercises are very interesting. In order for the other beginners to get to learn the basic usage of the language faster, I have compiled the results of my exercises for your reference. As I am a foreign student, this exercise is written in English. Most of the exercises come from 《C语言初学者趣味编程100例》(贾蓓/郭强/刘占敏). A small number of cases come from the Internet. If any case violates your rights, please tell me, and I will delete it as soon as possible.

Q19.Autoconservative number

Question:
Autoconservative number is the mantissa of the square of a number equal to the number itself. For example:52 = 25 252 = 625 762 = 5776 93762 = 87909376.Find all the Autoconservative number within 100000.
Python Code:

import time
start=time.time()


def zishoushu(a):
   b=a       
   list1=[]
   while a>0:
      list1.append(a%10)
      a=a//10
   c=pow(b,2)
   list2=[]
   j=0
   while c>0:
      list2.append(c%10)       
      c=c//10
   for i in range(len(list1)):
      if list1[i]==list2[i]:
         j=j+1   
   if j==len(list1):
      print(b)       

def zishoushu1(a):
   b=a       
   list1=[]
   while a>0:
      list1.append(a%10)
      a=a//10
   c=pow(b,2)
   d=c%pow(10,len(list1))
   if d==b:
      print(b)

for x in range(1,1000000):
   zishoushu1(x)

end=time.time()
print(end-start)

Running Results:
1
5
6
25
76
376
625
9376
90625
109376
890625
7.59375

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值