Skip to content

Instantly share code, notes, and snippets.

@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 05:40
Sum all nums
def tally_nums(*numbers):
total = 0
for n in numbers:
total += n
print(total)
if __name__ == "__main__":
tally_nums(1, 1, 1.3, 4.6)
tally_nums(4, 5, 6, 7, 8, 9)
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 05:42
Variable Number of Arguments
def tally_nums(*numbers):
total = 0
for n in numbers:
total += n
print(total)
if __name__ == "__main__":
tally_nums(1, 1, 1.3, 4.6)
tally_nums(4, 5, 6, 7, 8, 9)
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 06:40
Conditionals
def forecast(rain_chance, temp):
if rain_chance >= 60 and temp > 70:
print(
f"With a {rain_chance}% chance of rain today, don't forget your umbrella!")
elif rain_chance <= 30 and temp < 80 and temp > 60:
print("Enjoy the beautiful weather today")
elif rain_chance >= 60 and temp < 40:
print("Its going to be a cold and wet day today. Dress appropriately and be safe out there.")
elif rain_chance == 0 and temp < 40:
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 16:35
Conditionals 1
def main(a, b):
if a > b:
print("A is greater than b.")
elif a == b:
print("A is equal to b")
else:
print("A is less than b")
if __name__ == "__main__":
main(5, 10)
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 17:18
While Loop
def while_loop():
x = 0
while x < 5:
print(x)
x += 1
if __name__ == "__main__":
while_loop()
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 17:34
For loop
def for_loop():
the_list = [1, 2, 3, 4, 5]
for each_individual_value in the_list:
print(each_individual_value)
if __name__ == "__main__":
for_loop()
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 18:11
Index in List
days_of_week = ["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"]
days_of_week[0]
@codetombomb
codetombomb / hello_world.py
Last active September 24, 2020 18:51
Index in list
days_of_week = ["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"]
first_index = days_of_week[0]
print(first_index)
@codetombomb
codetombomb / hello_world.py
Created September 24, 2020 18:30
enumerate
def print_days():
days_of_week = ["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"]
for i, d in enumerate(days_of_week):
print(i, d)
if __name__ == "__main__":
print_days()
@codetombomb
codetombomb / hello_world.py
Last active September 24, 2020 19:01
Multiple Params
def introduction_with_language(name, language):
print(f"Hi, my name is {name} and I am learning to program in {language}.")
if __name__ == "__main__":
introduction_with_language("Tom", "Python")