In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to judge even numbers in Python. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
First, judge odd and even numbers
The smallest even number of natural numbers greater than 0 is 2.
The characteristics of the next even number 2, 4, 6, 8, 10...
According to the law of the above numbers, we can draw the conclusion that all even numbers are integral multiples of the minimum even number 2.
Question: so, how to tell whether a number is even?
Answer:
Judge an even number: if a number is divided by 2 and the remainder is 0, then the number is even, otherwise it is odd.
Actual combat cases in this section
Requirement: the user enters an integer, which represents the number of integers generated at random (the range of random numbers is between 1-100). The output result is that how many of the randomly generated numbers are even numbers, and what are these numbers?
For example:
User input 10
The system begins to randomly generate 10 random integers between 1 and 100
Output result: a total of 5 integers are generated, which are: 2, 10, 30, 36, 60
The thinking of software program practice and analysis:
1. User input uses input function
2. The number of cycles is required
3. Randomly generate numbers between 1 and 100
4. Judge whether it is an integer, calculate the number of integers, and save these integers
5. Output result
So, how to judge odd numbers?
In fact, as long as the opposite side is fine, that is, the case of numb% 2 is odd.
II. Summary and emphasis
1. Master and judge the parity of a number
2. Master the use of random numbers
3. Master the use of circulation
Knowledge source code for this issue:
From random import randint
# n represents the number of output n=input ("Please input how many integers need to be randomly generated?") N=int (n) x=0count=0 # number of records oushu= "" # saves an even number of while x
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.