In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "what are the common basic algorithm problems in Python". The editor shows you the operation process through actual cases, the operation method is simple and fast, and it is practical. I hope this article "what are the common basic algorithm problems in Python" can help you solve the problem.
1. Find the sum of all even numbers within 100 (including 100)
Range (start,end,step) this sequence generator, like the syntax of that slice, contains the head without the tail, and step is the step size, so there is no need to judge j here. For these simple sums of odd numbers, even numbers, multiples of n, and so on, you can do so.
For j in range (0meme 101jue 2):
S = s + j
Print (s)
two。 Find the nth Fibonacci number
This is to find the n-bit Fibonacci number, you can try a variety of ways to do it, I will not do much demonstration, if you want to find all the Fibonacci numbers in front of n (including n), just create a list and save it. I hope you can do it. Deepen the use of the list method.
# Fibonacci series: 1, 1, 1, 2, 3, 5, 5, 8, 13, 21, 34, 55.
# starting from the third place: the latter number is equal to the sum of the first two numbers
N = int (input ('Please enter the Fibonacci number you require:'))
A = 0
B = 1
For i in range (n):
# c = a
# a = b
# b = c + b
# the above three forms can be abbreviated as follows:
A _ b = _
Print (a)
3. Calculate the number of daffodils
I have defined a function to find the number of daffodils in n digits, but the number of daffodils is the sum of ten digits, hundred digits and the third power in 100-1000, which is equal to its own number. I just make an analogy, of course, I can not define a function, and directly use input to enter an n or give a value of n.
Def get_Narcissistic (n):
For i in range (pow (10 ~ ~ N), pow (10 ~ ~ (n)):
S = 0
For j in range (n):
S = s+pow (iCompact 10 percentile JJJ, n)
If iTunes:
Print (I)
Get_Narcissistic (3)
# 153
# 370
# 371
# 407
4. Print 99 multiplication table
Used to understand the use of loops
# axi0
# while a
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.