当前位置:网站首页>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 :
边栏推荐
- Three tier architecture experiment
- Global and China financial guarantee marketing strategy and channel dynamic construction report 2022
- PHP and WMI – explore windows with PHP
- Mount command - file system mount
- RM command – remove file or directory
- Day21 JMeter usage basis
- Find command – find and search for files
- Laravel8+ wechat applet generates QR code
- Methods for obtaining some information of equipment
- Notes on dashboard & kuboard installation in kubernetes cluster
猜你喜欢
Part 34 of SAP ui5 application development tutorial - device adaptation of SAP ui5 application based on device type

General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
SAP ui5 application development tutorial 32 - how to create a custom SAP ui5 control
How SAP ui5 device type detection device API works

Laravel8+ wechat applet generates QR code

Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
Vscode voice notes to enrich information (Part 1)

Soft exam information system project manager_ Management Science (Operations Research) 2--- senior information system project manager of soft test 034

Rhcsa--- day 6 operation

Vegetables sklearn - xgboost (2)
随机推荐
Getting started with mongodb
Global and Chinese benzoic acid market competition strategy and demand scale forecast report 2022
Day21 JMeter usage basis
RM command – remove file or directory
Cat command – display the file contents on the terminal device
Mongodb delete data
Getting started with Silverlight development 1
Hands on deep learning (III)
C switch nested syntax
HCIP Day 16
Echo command – output a string or extract the value of a shell variable
[open source sharing] deeply study KVM, CEPH, fuse features, including open source projects, code cases, articles, videos, architecture brain maps, etc
Yunda's cloud based business in Taiwan construction 𞓜 practical school
MV command – move or rename files
You can't specify target table for update in from clause error in MySQL
[data visualization application] draw spatial map (with R language code)
delphi-UUID
Three tier architecture experiment
Report on the application prospect and investment potential of global and Chinese cell therapy industry 2022-2028
What is the IP address