Last active
September 27, 2021 23:41
-
-
Save rockink/e4a10b44551b435cf0b9d0d9e80b2ef2 to your computer and use it in GitHub Desktop.
This file contains 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
# printing can print any number of parameters | |
def just_print(): | |
print("Hello") | |
print("Hello", "World") | |
print("Hey", "there", "hello", "World") | |
print("Hey there hello World") | |
# ------------------------------------------------------------------- | |
def print_fullname(first_name, last_name): | |
fullName = first_name + " " + last_name # there is NO SPACE in between! | |
print("FullName of employee is ", fullName) | |
print_fullname("Scooby", "Doo") | |
print_fullname("Saggy", "") # I have no idea what his last name is | |
print_fullname("Velma", "") | |
# ------------------------------------------------------------------- | |
# accessing each from the collection. | |
def print_from_string(text): | |
for letter in text: | |
print(letter) | |
print_from_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
print_from_string("Scooby") | |
def print_from_list(collection): | |
for item in collection: | |
print(item) | |
print_from_list(["honda", "tesla", "nissan", "chevy"]) | |
print_from_list(["Boston", "Quincy", "Brighton", "Allston"]) | |
# function that returns | |
def sum_from_list(collection): | |
total = 0 | |
for item in collection: | |
total = total + item | |
return total | |
print("Sum is ", sum_from_list([1, 2, 3, 4, 5])) | |
print("Another sum is", sum_from_list([11, 22, 33, 44, 55])) | |
# ------------------------------------------------------------------------ | |
def odd_or_even(number): | |
# I want to know if a number if odd or even | |
if number % 2 == 0: # % is remainder. Eg. 3 % 2 = 1, or 7 % 5 = 2, 10 % 5 = 0 | |
print("Even Number") | |
else: | |
print("Odd Number") | |
odd_or_even(1) | |
odd_or_even(2) | |
odd_or_even(300) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment