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
| import random, time | |
| BAR = chr(9608) # Character 9608 is "█" | |
| def main(): | |
| # simulate a download | |
| print("Progress bar simulation") | |
| bytes_downloaded = 0 | |
| download_size = 2048 | |
| while bytes_downloaded < download_size: |
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
| import random | |
| secret_number = random.randint(1, 9) | |
| print("You have 5 tries to guess the secret number (1-9)") | |
| while True: | |
| try: | |
| player_guess = int(input("Type your guess >>> ")) | |
| if player_guess == secret_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
| import random | |
| secret_number = random.randint(1, 9) | |
| print("You have 5 tries to guess the secret number (1-9)") | |
| while True: | |
| try: | |
| player_guess = int(input("Type your guess >>> ")) | |
| if player_guess == secret_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
| import random | |
| import time | |
| rock = 1 | |
| paper = 2 | |
| scissor = 3 | |
| def cpu_intelligence(): | |
| cpu = random.randint(1, 3) | |
| if cpu == 1: |
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
| def palindrome(word): | |
| return word == word[::-1] | |
| input_word = input("Enter a word: ") | |
| if palindrome(input_word): | |
| print("The word is a palindrome") | |
| else: | |
| print("The word is not a 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
| """ | |
| Create a program that asks the user for a number and then prints out a list of all | |
| the divisors of that number. (If you don’t know what a divisor is, it is a number | |
| that divides evenly into another number. | |
| For example, 13 is a divisor of 26 because 26 / 13 has no remainder. | |
| """ | |
| def divisor(n): | |
| for i in range(1, n+1): |
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
| import random | |
| def play_guessing_game(): | |
| # GENERATE A RANDOM NUMBER BETWEEN 1 AND 100 | |
| secret_number = random.randint(a=1, b=100) | |
| attempts = 0 | |
| guessed = False | |
| print("\nwelcome to the Handson's Number Guessing Game") | |
| print("I am thinking of a number between 1 and 100.") |
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
| # SECOND EXERCISE ON PRACTICEPYTHON.ORG | |
| def even_or_odd(number): | |
| if number % 2: | |
| return "Even" | |
| else: | |
| return "Odd" | |
| print(even_or_odd(4)) |
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
| # THIRD EXERCISE ON PRACTICEPYTHON.ORG | |
| # Creating the list | |
| a = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
| # Checking if the number is less then 5 | |
| def print_less_than_5(list): | |
| for number in list: | |
| if number < 5: | |
| print(number) |