What I have so far that works just fine with a positive integer input. The purpose is to calculate the square of each number between 0 and the input.
x = int(input("Please enter a number: "))
for x in range(1, x+1):
print(x ** 2)
This is including a if/else to make sure the input is a positive integer but it ends if it is negative instead of going back to asking again. Appreciate any help.
x = int(input("Please enter a number: "))
if x < 0:
print("That is not a positive number, try again.")
else:
for x in range(1, x+1):
print(x ** 2)
Aucun commentaire:
Enregistrer un commentaire