Skip to content

Instantly share code, notes, and snippets.

@DixieKorley
Last active June 24, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DixieKorley/6427e3f3532f3c4e916f022ab3615bff to your computer and use it in GitHub Desktop.
Save DixieKorley/6427e3f3532f3c4e916f022ab3615bff to your computer and use it in GitHub Desktop.
Exercises from Practice Python
from datetime import datetime
"""Character Input Exercise"""
name = input("Hi there. What is your name? ")
age = input("Hey, " + name + ", how old are you? ")
year = datetime.today().year
year_at_hundred = year + (100 - int(age))
end_message = "Nice! Sounds like you will be a 100 in " + str(year_at_hundred) + "!"
print(end_message)
keep_going = input("Wanna read this on repeat? Y or N? ")
if keep_going == "Y" or keep_going == "y":
repeat_number = input("Ok! Type any number: ")
print(int(repeat_number) * (end_message + "\n"))
print("Finished! All done.")
elif keep_going == "N" or keep_going == "n":
print(" ____ _____ _____ __ __ _ _")
print("/ ___|| ____| ____| \ \ / // \ | |")
print("\___ \| _| | _| \ V // _ \ | |")
print(" ___ | |___| |___ | |/ ___ \|_|")
print("|____/|_____|_____| |_/_/ \_(_)")
"""List Less Than Ten"""
# Print less than five
def print_less_than_five(nums):
for num in nums:
if num < 5:
print(num, sep=', ', end=".")
# Testing
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
print(print_less_than_five(a))
# One liner
print("New List: ", list(filter(lambda x: x < 5, a)))
# Smaller than input
number = int(input("Enter a number: "))
print("User List: ", list(filter(lambda x: x < number, a)))
"""Odd or Even"""
number = input("Enter a number: ")
number = int(number)
if number % 4 == 0:
print("I have a multiple of 4.")
if number % 2 == 0:
print("I have even number.")
else:
print("I have an odd number.")
num = input("Enter another number: ")
check = input("Enter a second number: ")
if int(num) % int(check) == 0:
print("You have an even number!")
else:
print("Not an even number.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment