Home » Python programs

Python | Print all numbers between 1 to 1000 which are divisible by 7 and must not be divisible by 5



Here, we are going to implement a Python program that will print all numbers between 1 to 1000, which are divisible by 7 and must not be divisible by 5.
Submitted by IncludeHelp, on August 09, 2018

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.

Example:

    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).
  • 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)) ).
  • 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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Quick links
Latest articles, Internship, Members
New...
Coding problems, Algorithms, Discrete Mathematics, Big data
Languages
C, C++, C++ STL, Java, Data Structure, C#.Net, Android, Kotlin, SQL
Web
PHP, Python, JavaScript, CSS, Ajax, Node.js, Web prog.
Programs
C, C++, DS, Java, C#, Python
Aptitude
C, C++, Java, DBMS
Interview
C, Embedded C, Java, SEO, HR
CS Subjects
CS Basics O.S. Networks DBMS Embedded Systems Cloud Computing Machine learning CS Organizations Linux DOS
More...
Articles, Puzzles, News/Updates


Recommended posts
C Tips & Tricks, C++ Tips & Tricks
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distros of 2018
C programming optimization techniques
Differences b/w C & Embedded C?
Embedded C Interview Q. & A.
C programming tips for Embedded Development
Basic rules of writing a C program
Important points (rules) to remember while writing C/C++ program
Top 5 Websites for solving programming challenges
Read more...


Others...
Computer G.K. (MCQ)
Most viewed pages...
Categories...



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.