python1到100能被5整除_python数字整除_Python打印1到
1000之间的。。。
python 数字整除
Given a range (which is 1 to 1000) and we have print all numbers which are divisible bye 7 and not divisible by 5 in python.
给定⼀个范围(1到1000),我们打印了所有在python中可被7整除⽽不能被5整除的数字。
Example:
python生成1到100之间随机数例:
Input:
Given input range is 1 to 1000
Output:
7, 14, 21, 28, 42, 49, 56, ...
Logic:
逻辑:
To implement this logic, we will use a for and in loop with range() method. The statement of range() method with the minimum to maximum range is range(begin, end+1).
为了实现此逻辑,我们将使⽤for和in循环with range()⽅法。 范围从最⼩到最⼤的range()⽅法的语句是range(begin,end + 1) 。
And, check the condition, that value should be divisible by 7 and should not be divisible by 5 (example code: ((cnt%7==0) and (cnt%5!=0)) ).
并且,检查条件,该值应可被7整除,⽽不能被5整除(⽰例代码: ((cnt%7 == 0)和(cnt%5!= 0))) 。
If condition is true, print the numbers.
如果条件为真,则打印数字。
Program:
程序:
# define range in variables
# so that we can change them anytime
begin = 1
end = 1000
# loop to check and print the numbers
# which are divisible by 7 and not
# divisible by 5
for cnt in range(begin, end+1):
if( cnt%7==0 and cnt%5!=0 ):
print cnt, # command after cnt will print space
Output
输出量
7 14 21 28 42 49 56 63 77 84 91 98 112 119 126 133 147 154 161 168 182 189 196 203 217 224 231 238 252 259 266 273 287 294 301 308 322 329 336 343 357 364 371 378 392 399 406 413 427 434 441 448 462 469 476 483 497 504 511 518 532 539 546 553 567 574 581 588 602 609 616 623 637 644 651 658 672 679 686 693 707 714 721 728 742 749 756 763 777 784 791 798 812 819 826 833 847 854 861 868 882 889 896 903 917 924 931 938 952 959 966 973 987 994
python 数字整除

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。