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
| #Collatz Sequence | |
| def collatz(number): | |
| #If number is even then divide by 2 and then return number | |
| if number % 2 == 0: | |
| print(number // 2) | |
| return number // 2 | |
| #If number is odd then times the number by 3 and add 1 then return number | |
| elif number % 2 == 1: | |
| result = 3 * number + 1 | |
| print(result) |
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
| # Guessing game from 1-10 | |
| import random | |
| answer = random.randint(0, 3) | |
| print("Please guess a number from 1-10!") | |
| guess = int(input()) | |
| if (guess != answer): | |
| if (guess < answer): | |
| print("Guess higher!") | |
| else: # If guess is higher than the answer |
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
| age = 24 | |
| #Old way | |
| print("My age is " + str(age) + " years") | |
| #New way | |
| print("My age is {0} years".format(age)) | |
| print("There are {0} day in {1}, {2}, {3}, {4}, {5}, {6} and {7}".format(31, "January", "March", "May", "July", "August", "October", "December")) |