Issue
number = int(input("Enter any non-negative and non-zero integer number: "))
counter = 0
while number > 0 and number != 1:
counter = +1
if number % 2 == 0:
number = number/2
if number % 2 == 0:
number = number/5
else:
number = (number*3)+1
else:
if number % 2 == 0:
number = number/2
else:
number = (number*3)+1
print("Your number took", counter, "steps")
Solution
You need to change the counter= +1
to counter += 1
, and you can change your if-else statement like this:
number = int(input("Enter any non-negative and non-zero integer number: "))
counter = 0
while number > 0 and number != 1:
counter += 1
print(number)
if number % 2 == 0:
number = number/2
else:
number = number*3+1
print("Your number took", counter, "steps")
Answered By - Marsolgen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.