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
| #!/usr/bin/env python3 | |
| import datetime | |
| name = input("Please enter your name here > ") | |
| age = int(input("Please enter your age here > ")) | |
| difference = 100 - age | |
| current_year = datetime.datetime.now().year | |
| string = "{0}, the year you will turn 100 will be {1}".format(name, current_year + difference) |
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
| #!/usr/bin/env python3 | |
| number = int(input("Please enter a number > ")) | |
| remainder = number % 2 | |
| if remainder: | |
| print("It's seems that {0} is odd.".format(number)) | |
| else: | |
| print("It's seems that {0} is even.".format(number)) |
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
| #!/usr/bin/env python3 | |
| a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
| # Print all elements that are less than 5 | |
| for i in a: | |
| if i < 5: | |
| print(i) | |
| print() | |
| # Make a new list with the elements less than 5 |
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
| #!/usr/bin/env python3 | |
| def get_divisors(n): | |
| d = 1 | |
| while d * d <= n: | |
| if n % d == 0: | |
| print(d) | |
| # If d is a divisor, then number / d is also a divisor | |
| # But we need to be careful with square numbers |
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
| #!/usr/bin/env python3 | |
| import random | |
| def return_common_elements(first_list, second_list): | |
| first_list.extend(second_list) | |
| new_list = list(set(first_list)) | |
| return new_list |
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
| #!/usr/bin/env python3 | |
| string = list(input("Please enter a string > ")) | |
| reverse_string = string.copy() | |
| reverse_string.reverse() | |
| if string == reverse_string: | |
| print("Palindrome.") | |
| else: | |
| print("Not palindrome.") |
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
| #!/usr/bin/env python3 | |
| a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] | |
| new_list = [element for element in a if element % 2 == 0] | |
| print(new_list) |
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
| #!/usr/bin/env python3 | |
| choices = 'rock', 'paper', 'scissors' | |
| EQUALITY = "Oh, no! There is no winner, it's equality!" | |
| PLAYER_ONE_WINNER = '...And the winner is: ~Player One~' | |
| PLAYER_TWO_WINNER = '...And the winner is: ~Player Two~' | |
| print('''Welcome to the "Rock, Paper and Scissors" Game! | |
| The rules are simple: | |
| 1. Each player chooses what he/she wants from the following list: rock, \ |
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
| #!/usr/bin/env python3 | |
| import random | |
| number = random.randint(1, 9) | |
| guesses = 0 | |
| user_input = input('Enter a number (between 1 and 9) [>>>] ') | |
| while user_input != 'exit': | |
| if int(user_input) < number: |
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
| #!/usr/bin/env python3 | |
| import random | |
| MAX_ELEMENT_VALUE = 100 | |
| MAX_ELEMENTS = 20 | |
| # Randomly generate two lists | |
| # Noob way |
OlderNewer