An introductory course to Python programming
Last active
August 28, 2025 09:37
-
-
Save vicradon/5a8530545d63cc6037689c7a6143433a 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
| print("What's good, world?") |
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
| my_name = "Mr. Brother Man" | |
| my_age = 42 | |
| my_interests = ["Anime", "Archery", "Skating"] | |
| print("My name is", my_name, "and I am", my_age, "and my interests are", *my_interests) |
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
| message = f"My name is {my_name} and I am {my_age} and my interests are {my_interests[0]}, {my_interests[1]}, and {my_interests[2]}" | |
| print(message) |
my_name is a string. It is used for things like names, and natural language
my_age is an integer. It is used for whole numbers, both negative and positive
my_interests is a list. It is used for grouping/ordering related variables
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
| input("What is your name: ") | |
| name = input("What is your name: ") | |
| print(name) |
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
| name = input("What is your name: ") | |
| age = input("What") | |
| interest1 = input("What is your number 1 interest: ") | |
| interest2 = input("What is ") | |
| interest3 = input("What ") | |
| combined = f"Your name is {name} and" | |
| print(combined) |
Notice how you needed to define interest1, interest2, and interest3 manually? What if there was a way to write less code? That is where a for-loop comes in.
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
| name = input("What is your name: ") | |
| age = input("What is your age: ") | |
| interests = [] | |
| for i in range(3): | |
| interest = input(f"What is your number {i} interest: ") | |
| interests.append(interest) | |
| interests_string = ", ".join(interests) | |
| combined = f"Your name is {name} and you are {age} years old with interests in {interests_string}" | |
| print(combined) |
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
| name = input("What is your name: ") | |
| age = input("What is your age: ") | |
| interests = [] | |
| i = 1 # increment variable | |
| while i <= 3: # | |
| interest = input(f"What is your number {i} interest: ") | |
| interests.append(interest) | |
| i += 1 # iteration | |
| interests_string = ", ".join(interests) | |
| combined = f"Your name is {name} and you are {age} years old with interests in {interests_string}" | |
| print(combined) |
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 collect_input(): | |
| name = input("What is your name: ") | |
| age = input("What is your age: ") | |
| interests = [] | |
| for i in range(3): | |
| interest = input(f"What is your number {i} interest: ") | |
| interests.append(interest) | |
| interests_string = ", ".join(interests) | |
| return f"Your name is {name} and you are {age} years old with interests in {interests_string}" | |
| collect_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
| def add(num1, num2): | |
| return num1 + num2 | |
| number_sum = add(2, 3) | |
| print(number_sum) | |
| ''' | |
| num1 is the first parameter | |
| num2 is the second parameter | |
| 2 is the first argument (things passed to functions) | |
| 3 is the second argument | |
| return is a keyword for returning from a function | |
| ''' |
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 subtract(num1, num2): | |
| return num1 - num2 | |
| difference = subtract(7, 3) | |
| print(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
| def divide(num1, num2): | |
| return num1/num2 | |
| print("5 divide by 2 is", divide(5,2), "\n\n") | |
| print("3 divide by 0 is", divide(3, 0)) # throws error |
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 divide(num1, num2): | |
| try: | |
| return num1/num2 | |
| except Exception as e: | |
| print(str(e)) | |
| print("5 divide by 2 is", divide(5,2)) | |
| print("3 divide by 0 is", divide(3, 0)) # throws error |
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 divide(num1, num2): | |
| try: | |
| return num1/num2 | |
| except ZeroDivisionError: | |
| print("You attempted to divide by zero") | |
| print("5 divide by 2 is", divide(5,2)) | |
| print("3 divide by 0 is", divide(3, 0)) # throws error |
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
| class Calculator: | |
| def __init__(self): | |
| pass | |
| def add(self): | |
| name = input("What is your name: ") | |
| age = input("What is your age: ") | |
| interests = [] | |
| for i in range(3): | |
| interest = input(f"What is your number {i} interest: ") | |
| interests.append(interest) | |
| interests_string = ", ".join(interests) | |
| return f"Your name is {name} and you are {age} years old with interests in {interests_string}" | |
| bank = Bank() | |
| bank.collect_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment