Use a Boolean variable like:
Print out even or odd based on the boolean flag.
Use Modulo arithmetic (remainder) to determine if the value is even or odd. C++, Java, and Python all use the % character.
Divide the number (r in your loop counter) by 2
If the remainder is 0, then the number is even, else it is odd
If the remainder is zero, set your boolean value to true, else set the boolean value to false, like:
boolean myflag=true where myflag is any variable name
Notice, no quotes around true.
In Python, the T in true is a capital T...print something like:
Note: You don't have to check to see if myflag==true
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.myflag = True
for i in range(200, 256):
myflag = i % 2 == 0 # Check if mod division is equal to zero a set result to myflag
By purchasing this solution you'll be able to access the following files: