Skip to content

Instantly share code, notes, and snippets.

View Ovicron's full-sized avatar
🐜

Ovicron

🐜
View GitHub Profile
@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 / 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!"
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.
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))
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))
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)
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.")
@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)