Dums3610
(Mohamed Dumbuya)
August 6, 2024, 4:46pm
1
I need help on how to write the following codes:
list of numbers 1 - 50
display numbers in 2’s or 4’s from this list.
the result of step 2 is to be displayed as TEXT instead of NUMBERS.
for e.g. all numbers that are multiples of 2: 2,4,6,8,10 etc. should be as displayed FOOT, but not as 2,4,6,8,10 as the case maybe.
c-rob
(Chuck R.)
August 6, 2024, 11:58pm
2
What is your code that you have tried so far?
You will have to do a loop. Do you know how to do that in Python?
An even number is a number divisible by 2 and has no remainder. The operator %
is called “modulus”. The code for this is:
if (num % 2) == 0:
print("This is an even number")
A number divisible by 4 with no remainder is similar.
if (num % 4) == 0:
print("This number is evenly divisible by 4")
Links
Here is more info on the modulus operator. Python Modulo in Practice: How to Use the % Operator – Real Python The modulus %
is for integers only.
This is a better site as well. The Python Modulo Operator - What Does the % Symbol Mean in Python? (Solved)