Input a list of expenses from the user and output (a) the sum, (b) flag those that are bigger than 100, (c) the sum of those smaller than 100, and (d) the sum of those bigger than 100. All outputs should show two decimal places and a currency symbol.
thresh = 100
expenses = input("Please enter expenses: ").split()
sum = 0
sum_small = 0
sum_big = 0
for expense in expenses:
expense = float(expense)
sum += expense
if expense > thresh:
print(" Flag: ${:.2f}".format(expense))
sum_big += expense
else:
sum_small += expense
print("Sum: ${:.2f}".format(sum))
print("Small Sum: ${:.2f}".format(sum_small))
print("Big Sum: ${:.2f}".format(sum_big))
Input a list of words from the user as first1 last1 first2 last2 ... and create (and print) a list [[first1 last1], [first2 last2], ...]
names = []
flat_names = input("Please enter names: ").split()
first = True
for flat in flat_names:
if first:
names.append([flat])
else:
names[len(names)-1].append(flat)
first = not first
print(names)
Input a list of words from the user (assume all lower case), as well as their favorite letter (also lower case); now spell each word emphasizing if the word is a favorite, and each letter as favorite or not (with OMG!!!).
words = input("Please enter words: ").split()
fave = input("Please enter favorite letter: ")
for word in words:
if fave in word:
print("{} (OMG!!!)".format(word))
else:
print(word)
for letter in word:
if letter == fave:
print(" {} (OMG!!!)".format(letter))
else:
print(" {}".format(letter))
Given a list-of-lists of passengers (name, age, citizenship, passport number) and input search criteria (minimum age, maximum age, word to find in their name, and citizenship), find the suspect(s) that match (with a sad-face if no one found).
passengers = [
[['alice', 'bob'], 39, 'usa', 111],
[['bob', 'carol'], 42, 'usa', 22],
[['carol', 'dan'], 27, 'france', 3],
[['dan', 'erin'], 57, 'usa', 4444],
[['erin', 'alice', 50, 'south africa', 55555]]
]
min_age = int(input("Enter minimum age: "))
max_age = int(input("Enter maximum age: "))
name_part = input("Enter either first or last name: ")
citizenship = input("Enter citizenship: ")
found = False
for person in passengers:
if (name_part in person[0]) and (person[1] >= min_age) and (person[1] <= max_age) and (person[2] == citizenship):
found = True
print("Found: {} ({} {}, age {}, from {})".format(person[3], person[0][0], person[0][1], person[1], person[2]))
if not found:
print("No suspects found :(")