i start learning python i write this code to check if the number is even or odd , if the number is even then take that number and / 2 if the number is odd then do : 3 * number + 1
i dont know where to put while
my code:
def collatz(number):
if number % 2 == 0:
return number / 2
else:
return 3 * number + 1
print("enter the number ")
qassam = int(input())
print(collatz(qassam))
i want to exit when the result of any if conditions = 1 how to do that ?
Aucun commentaire:
Enregistrer un commentaire