Skip to content

Instantly share code, notes, and snippets.

View Ovicron's full-sized avatar
🐜

Ovicron

🐜
View GitHub Profile
@Ovicron
Ovicron / Calculator.py
Created April 22, 2020 15:12
my basic calculator
def basic_calculator():
num1 = float(input(" Enter First Number: "))
op = input("Enter Operator: ")
num2 = float(input("Enter Second Number: "))
if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "/":
print(num1 / num2)
def calc_age(current_year, birth_year):
age = current_year - birth_year
return age
my_age = calc_age(2020, 2001)
print(f"I am {my_age} years old.")
def repeat_song(repeats, num_repeats=1):
return repeats*num_repeats
merrily = repeat_song("Merrily ", 4)
lyrics = repeat_song("Row ", 3) + "Your Boat. Gently down the stream. " + merrily + "Life is about a dream!"
song = repeat_song(lyrics)
train_mass = 22680
train_acceleration = 10
train_distance = 100
bomb_mass = 1
def f_to_c(f_temp, c_temp):
c_temp = (f_temp - 32) * 5/9
return c_temp
f100_in_celsius = (f_to_c(100))
num1 = float(input("Enter first num for AVG: "))
num2 = float(input("Enter second num for AVG: "))
def avg_num(num1, num2):
return (num1 + num2) / 2
print(avg_num(num1, num2))
def dog_years(name, age):
# Returned function parameters (name/age) and added string to RETURN.
return name+", you are "+str(age*7)+" years old in dog years"
# When you print/call the function and give it values,
# it will print name + age INCLUDING string from RETURN.
@Ovicron
Ovicron / boolean_operators.py
Last active April 23, 2020 20:55
if, and, not
# (boolean operators)
# if statements = combining with function parameters (gpa/class_credits)
# and operator = combining True/False expressions (eg; My car is broken "and" it is raining)
# not operator = Reverse the result, returns False if the result is true (Can be combined with "and")
# for last "if" statement, you can also use "else" because that would print the final possible outcome of the function.
def graduation_requirements(gpa, class_credits):
if (gpa >= 2.0) and (class_credits >= 120):
return "You meet the requirements to graduate!"
@Ovicron
Ovicron / elif_statements.py
Created April 23, 2020 21:08
Else - If statements notes.
# else if statements (elif)
# we use "else-if" because using "if" statements for all of the statements would result in ALL IN RANGE being PRINTED!
def grade_converter(gpa):
if gpa >= 4.0:
return "A"
elif gpa >= 3.0:
return "B"
@Ovicron
Ovicron / try_and_except.py
Created April 23, 2020 21:32
try/except statements.
# try and except statements (Make errors more readable or hide them)
def raises_value_error():
try:
# Find errors with code in between "try" and "except" statements
raise 0 / 0
@Ovicron
Ovicron / movie_rating_function.py
Created April 24, 2020 19:55
shows me inbetween comparison
def movie_review(rating):
if rating <= 5:
return "Avoid at all costs!"
elif 5 < rating < 9: # This shows us an in between comparison
return "This one was fun."
elif rating >= 9:
return "Outstanding!"