cs160examples/week6/inksTuple.py

51 lines
1.7 KiB
Python

def main():
inkNames = []
inkColors = []
isShimmered = []
toContinue = True
while toContinue:
option = input("Enter an ink? Yes/No: ").lower()
if option == "yes":
inkN = input("Enter the name of the ink: ").lower()
inkC = input("Enter the color of the ink: ").lower()
shimmered = input("Is it shimmered? Yes/No: ").lower()
inkNames.append(inkN)
inkColors.append(inkC)
isShimmered.append(shimmered)
elif option == "no":
toContinue = False
else:
print("Sorry, couldn't understand that")
#print(f"These are our ink names {inkNames}")
#print(f"These are the ink colors {inkColors}")
#print(f"This is whether they have shimmer {isShimmered}")
print("Ink Name | Ink Color | Shimmered?")
for i in range(0, len(inkNames)):
print(f"{inkNames[i]} | {inkColors[i]} | {isShimmered[i]}")
# count how many have shimmer
numShimmered = 0
for s in isShimmered:
if s == "yes":
numShimmered = numShimmered + 1
print(f"You have {numShimmered} inks with glitter. Watch out for clogs.")
# count how many inks of the same color there are
largestNumColors = 0
largestColor = ""
# for each color c in the list of colors
# we need to count how many times it shows up in the list
# we do this in the inner loop (the one with d as the loop variable)
# otherwise, it's just like finding the max element of a list of numbers
for c in inkColors:
numTimes = 0
for d in inkColors:
if d == c:
numTimes = numTimes + 1
if numTimes > largestNumColors:
largestNumColors = numTimes
largestColor = c
print(f"The color you have the most of is {largestColor} and you have {largestNumColors} inks of this color.")
main()