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
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) |
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
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) |
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
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: |
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
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) |
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
def while_loop(): | |
x = 0 | |
while x < 5: | |
print(x) | |
x += 1 | |
if __name__ == "__main__": | |
while_loop() |
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
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() |
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
days_of_week = ["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"] | |
days_of_week[0] |
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
days_of_week = ["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"] | |
first_index = days_of_week[0] | |
print(first_index) |
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
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() |
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
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") |