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
| for i in range(n): | |
| i += 1 | |
| i -= 1 | |
| print(i) |
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
| for i in range(n): | |
| for j in range(n): | |
| print(i + j) | |
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
| for i in range(n): | |
| for j in range(n): | |
| for h in range(n): | |
| print(i + j + h) | |
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 print_to_zero(n): | |
| if n < 0: | |
| return | |
| print(n) | |
| print_to_zero(n - 1) | |
| print_to_zero(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
| float("self-taught") |
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 get_input(): | |
| choices = ["rock", "paper", "scissors"] | |
| uinput = input("Choose rock paper or scissors") | |
| if uinput not in choices: | |
| print("invalid option") | |
| return | |
| print("You picked {}".format(uinput)) | |
| return uinput | |
| get_input() |
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 string | |
| def generate_function(): | |
| """ Returns a secure password.""" | |
| password = '' #The password starts as an empty string. | |
| for i in range(random.randint(3, 5)): #We determine the length of the password by picking a random number between 3 and 5. | |
| # Each time through the loop we add 4 characters to the string, so each password will be between 12 and 20 characters. | |
| password += random.choice(string.punctuation) # The string module contains a variable called punctuation that |
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 = 20 |
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
| # list of correct number to guess | |
| guess = [1,3,5] | |
| while True: | |
| question = input("Enter q for quit or guess a number") | |
| if question == 'q': | |
| break | |
| try: | |
| if int(question) in guess: |
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
| string = "hello" | |
| # writing code that handles if whatever you are searching for isn't found with find | |
| result = string.find("z"): | |
| # This is bad because it is hard for another program to read | |
| if result == -1: | |
| raise ValueError("I couldn't find it") | |
| print(result) | |
| # writing code that handles if whatever you are searching for isn't found with index |