Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save CavaTrendy/856873e20a6443a5400eb01b0dc38717 to your computer and use it in GitHub Desktop.

Select an option

Save CavaTrendy/856873e20a6443a5400eb01b0dc38717 to your computer and use it in GitHub Desktop.
# Write a function named collatz() that has one parameter named number. If number is odd or even
#number is even, then collatz() should print number // 2 and return this value.
#If number is odd, then collatz() should print and return 3 * number + 1.
# First example def of collatz()
def collatz( number ):
if number % 2 == 0:
return " it is even number "
else:
return "it is an odd number"
number = int(input("input a number: "))
print( collatz( number ) )
# Second example def of collatz()
def collatz( number ):
if number % 2 == 0:
return " it is even number " , float(number / 2)
else:
return "it is an odd number" , 3*number + 1
number = int(input("input a number: "))
print( collatz( number ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment