I have been searching Stacked/Nested if else statements, elif's don't seem to work for what I need. The Aim is to print all even, square numbers, and cube numbers as well as highlight which ones are both square and Cube. This is the code i have:
import math
rn = 0
d=0
for n in range(1,100,1):
if rn is 0:
if n%2 is 0:
print(n, " is an even number")
else:
rn = 1
if math.sqrt(d) is int:
print(n, " is a square number")
if n**(1-3) is int:
print(n, " is a Cube number too")
continue
else:
print(n, "is only a square number")
continue
else:
rn = 1
if rn is 1:
if n**(1-3) is int:
print(n, " is a Cube only number")
else:
rn = 0
continue
The code is not moving on to the next if statements, before incrementing n.
output:
2 is an even number
4 is an even number
6 is an even number
Is there another way to continue or break but staying in the same loop? Thanks in advance
Aucun commentaire:
Enregistrer un commentaire