Need some help with this code. It calculates the factorial fine the first time around but as it loops in the while loop it seems to be storing the value and increments it. Any suggestions?
#Get number and store in variable, also declare and initialize factorial variable
number = int(input("Please enter a nonnegative integer number (or enter 0 to end program): "))
print()
factorial= 1
#Check if number is a negative integer and if it is, prompt for input again or give option to end program
if number <0:
while number !=0 and number <0:
print("You have entered a negative integer. Please try again.")
number = int(input("Please enter a nonnegative integer number (or enter 0 to end program): "))
print()
#Calculate and display factorial of number while input is valid
while number != 0 and number >=1:
#Calculate and display factorial value
while number >= 1:
factorial = factorial * number
number = number -1
print("The factorial for that number is: {}".format(factorial))
print()
#Get the next number
number = int(input("Please enter another nonnegative integer number or enter 0 to end program: "))
print()
#Check if newly entered number is a negative integer and if it is, prompt for input again or give option to end program
if number <0:
while number !=0 and number <0:
print("You have entered a negative integer. Please try again.")
print()
#Prompt again for valid nonnegative integer
number = int(input("Please enter a nonnegative integer number (or enter 0 to end program): "))
print()
You are not resetting the value of factorial in between runs of your while loop. You should move the line
factorial= 1
to be after
#Calculate and display factorial of number while input is valid
while number != 0 and number >=1: