# Jacob Powers - 9/21/2021
# I learned how to use if, else statements.
# I had no difficulties.
if True:
print("True means do something")
else:
print("Not True means do something else")
hot_tea = True
if hot_tea:
print("enjoy some hot tea!")
else:
print("enjoy some tea, and perhaps try hot tea next time.")
someone_i_know = False
if someone_i_know:
print("how have you been?")
else:
# use pass if there is no need to execute code
pass
# changed the value of someone_i_know
someone_i_know = True
if someone_i_know:
print("how have you been?")
else:
pass
#Code determines if sunny_today is true, and prints the relevant message.
sunny_today = True
if sunny_today:
print("It is sunny today!")
else:
print("It is not sunny today.")
sunny_today = False
if sunny_today:
print("It is sunny today!")
else:
print("It is not sunny today.")
# review code and run cell
# Code determines if user input of favorite_book is title case, and displays the appropriate message.
favorite_book = input("Enter the title of a favorite book: ")
if favorite_book.istitle():
print(favorite_book, "- nice capitalization in that title!")
else:
print(favorite_book, "- consider capitalization throughout for book titles.")
# review code and run cell
# Code determines if user input for a_number is a positive integer or not, and displays an appropriate message. If input is not a digit, it displays a second message stating that it is "more like a word".
a_number = input("enter a positive integer number: ")
if a_number.isdigit():
print(a_number, "is a positive integer")
else:
print(a_number, "is not a positive integer")
# another if
if a_number.isalpha():
print(a_number, "is more like a word")
else:
pass
# review code and run cell
# Code determines if the input for vehicle_type starts with a P, and displays an appropriate message.
vehicle_type = input('"enter a type of vehicle that starts with "P": ')
if vehicle_type.upper().startswith("P"):
print(vehicle_type, 'starts with "P"')
else:
print(vehicle_type, 'does not start with "P"')
# Code determines if the two following strings are in lowercase, and prints the appropriate message for each.
test_string_1 = "welcome"
test_string_2 = "I have $3"
if test_string_1.islower():
print("String 1 is in lower case.")
else:
print("String 1 is not in lower case.")
if test_string_2.islower():
print("String 2 is in lower case.")
else:
print("String 2 is not in lower case.")
# Code uses a function to test the three strings to see if any of them start with a lowercase w, and prints the appropriate message.
def w_start_test(test):
if test.startswith('w'):
print('"' + test + '"' + " Does start with a lowercase w.")
else:
print('"' + test + '"' + " Does not start with a lowercase w.")
test_string_1 = "welcome"
test_string_2 = "I have $3"
test_string_3 = "With a function it's efficient to repeat code"
w_start_test(test_string_1)
w_start_test(test_string_2)
w_start_test(test_string_3)