当前位置:网站首页>Exercise: completion
Exercise: completion
2022-06-25 06:20:00 【Dreamy spirit_ cq】
Complete
subject
Definition :
The sum of all the factors of a number ( except 1 And itself ) Equal to the number itself .
Click to see “ Complete ” Encyclopedia entry
Misreading questions
I put... In the title “ factor ” Understood as prime factor , First find the prime number that is not greater than the input integer , Find the prime factor and sum . Only to find 4 by “ Complete ”. After encyclopedia , I see. Yes “ All the factors ”, Modify the code , Use the perfect number 6、28 Trial code . To no avail !!!Why? 🧐🧐
I am not careful , Omit again “ True factor ” Medium 1.
Code running effect
Python Code
( If you can't make clear the function from the statement annotation , Please leave a message in the comment area for advice and discussion .)
#!/sur/bin/nve python
# coding: utf-8
number_s = ''' Complete Definition : The sum of all the factors of a number ( except 1 And itself ) Equal to the number itself . '''
def isw_number(num): #“ Complete ” confirm .
if sum([i for i in range(1, num) \
if num % i == 0]) == num:
# Parse out an integer “ True factor ” list , Sum and judge .
return num
#“ True factor ” And equals the number , Returns the completion , Not perfect, no return value .
input(isw_number(8128)) # Use the perfect number 8128 experiment on tempering with fire .
n = 10000
wang_numbers = [i for i in
map(isw_number, range(1, n + 1))
if i is not None]
s = f"1 ~ {n} Medium “ Complete ”:"
# call isw_number lookup 0 ~ 1×10**9 The perfections in .
print(f'\n\n\n{
" Find completion ":_^46}\
\n\n{
"":.^50}\
\n{
number_s}\
\n{
"."*50}\
\n\n\n{
s}{
wang_numbers}\
\n\n\n{
" The end ":_^50}\n')
“ Complete ” Functions use short sentences , Easier to read .
def isw_number(num): #“ Complete ” confirm .
factors = [] # initialization “ True factor ” list .
for i in range(1, num): # Traverses an integer smaller than the input integer , Seek “ All “ True factor ”.”
if num % i == 0: # Is the input integer true factor
factors.append(i) # Collect to “ True factor ” list .
if sum(factors) == num: # Input integer “ True factor ” The sum of the list is equal to the integer .
return num # The input integer is the completion , Returns the completion . Not perfect, no return value .
Related articles :
Last one : practice : Narcissistic number
[ Python Getting started ] 【Python 3.6.3】(https://www.runoob.com/manual/pythontutorial3/docs/html/)
A good writer recommends : Good habits of reliable programmers

Excellent articles :
- OPP The three major characteristics : In the package property
- Understand through built-in objects python'
- Regular expressions
- python in “*” The role of
- Python A complete self-study manual
- Walrus operators
- Python Medium `!=` And `is not` Different
- The right way to learn programming
source : Laoqi classroom
CSDN Practical skills blog :
边栏推荐
- The sum problem
- Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator
- Research Report on global and Chinese vaccine market profit forecast and the 14th five year plan development strategy 2022-2028
- Ethernet
- Guess the size of the number
- Echo command – output a string or extract the value of a shell variable
- Trial version of routing history and routing back and history of SAP ui5
- Go uses channel to control concurrency
- What is the slice flag bit
- Day21 performance test process
猜你喜欢
Linus' speech recordings, which were lost in 1994, were made public

Getting started with mongodb

3-7sql injection website instance step 3: attack type and attack strategy
Part 33 of SAP ui5 application development tutorial - trial version of responsiveness of SAP ui5 applications

Mongodb delete data

【LeetCode】40. Combined summation II (2 strokes of wrong questions)
Technology inventory: past, present and future of Message Oriented Middleware

Distributed solar photovoltaic inverter monitoring

Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?

IQ debugging of Hisilicon platform ISP and image (1)
随机推荐
JS implementation mouse can achieve the effect of left and right scrolling
Detailed explanation of @jsoninclude annotation in Jackson
Wireless industrial Internet of things data monitoring terminal
Sword finger offer II 095 Longest common subsequence
Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?
No one reads the series. Source code analysis of copyonwritearraylist
Personal blog system graduation project opening report
Ethernet
VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
Gb28181 protocol -- timing
Optimal Parking
Highway
[kicad image] download and installation
At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
[open source sharing] deeply study KVM, CEPH, fuse features, including open source projects, code cases, articles, videos, architecture brain maps, etc
Copying DNA
Day22 send request and parameterization using JMeter
D compile time reflection
How SAP ui5 device type detection device API works
Ifconfig command – displays or sets network devices