Created
December 15, 2017 06:24
-
-
Save CavaTrendy/856873e20a6443a5400eb01b0dc38717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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