- Access exercises (91)
- C# exercises (79)
- Excel exercises (278)
- Power Apps exercises (13)
- Power Automate exercises (18)
- Power BI exercises (139)
- Python exercises (28)
- Report Builder exercises (141)
- SQL exercises (198)
- SSAS exercises (51)
- SSIS exercises (46)
- SSRS exercises (99)
- VBA exercises (85)
- Visual Basic exercises (46)
Python | Sequences exercise | Print out numbers divisible by 3 but not by 2
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
In a new program, create a variable to hold the first 50 integers.
Loop over the values in this range, printing out those which are divisible by 3 but not by 2:
The program should produce this output. You can test whether one number is divisble by another by using the % symbol to find its remainder, and testing if this is 0 (for example 23 % 5 woudl give 3, the remainder when you divide 23 by 5).
While reflecting on whether you will ever use this program in anger, close it down!