listAssign1.py

listAssign1.py

listAssign2.py

listAssign3.py

listAssign4.py

# listAssign2.py
# Leen Saflo
# getting names and setting up random matches 

from random import *

players = []      # list of players

while True:
    names = input("enter names, (done to break) ")   
    if names == "done":
        break
    players.append(names)
if len(players) % 2 != 0:        # if the number is uneven add Bye
    players.append('Bye')

shuffle(players)

print("Round 1")
print("-------------------------")
for i in range(0,len(players),2):      # contin by 2 to pair players properly, printing player at every index
    print(f"{players[i]} vs {players[i+1]}")
print("-------------------------")

# listAssign1.py
# Leen Saflo
# to make a list of below average words from a game of scrabble

words = []        # list of words
score = []        # list of scores
belowAvg = []     # list of below average words

while True:
    wordsInput = input("Enter word ('done' to break): ")   # what words the user puts
    if wordsInput == "done":
        break
    words.append(wordsInput)
    scoreInput = int(input("Enter score: "))                # what scores the user puts 
    score.append(scoreInput)
    
avg = sum(score) / len(score)

for i in range(len(words)):
    if score[i] < avg:
        belowAvg.append(words[i])
print(f"Mr. McKenzie, don't use: {belowAvg}")
# listAssign3.py
# Leen Saflo
# to create a trivia of the prime ministers, displaying 10 questions with comments and result in percent

from random import *

# list of prime ministers
quest = ["Macodnonald", "Mackenzie", "Macdonald", "Abbott", "Thompson", "Bowell", "Tupper",   
     "Laurier", "Borden", "Borden", "Meighen", "King", "Meighen", "King", "Bennett", 
     "King", "Laurent", "Diefenbaker", "Pearson", "Trudeau", "Clark", "Trudeau", "Turner", 
     "Mulroney", "Campbell", "Chrétien", "Chrétien", "Martin", "Trudeau"]

# list of years
ans = ["1867 - 1873", "1873-1878", "1878-1891", "1891–1892 ", "1892–1894 ","1894–1896 ","1896 ","1896–1911 ","1911–1917 ","1917–1920 ",
          "1920–1921 ","1921–1926 ","1926 ","1926–1930 ","1930–1935 ","1935–1948 ","1948–1957 ","1957–1963 ",
          "1963–1968 ","1968–1979 ","1979–1980 ","1980–1984 ","1984 ","1984–1993 ","1993 ","1993–2003 ","2003–2006 ",
          "2006–2015 ","2015–now"]

# question numbers
qnum = list(range(29))
shuffle(qnum)

# correct answers
correct = 0

for i in range (10):
    pos = qnum[i]
    userAns = input(f" Who was the prime minister during {ans[pos]}: ")   
    if userAns == quest[pos]:
        print ("correct!")
        correct += 1
    else:
        print (f"incorrect, the answer was {quest[pos]}")

percent = (correct/10)*100

if percent >= 80:
    print (f" you have recieved {percent:.2f}%, you definitely payed attention in history class.")
elif percent >= 60:
    print (f" you have recieved {percent:.2f}%, well done.")
elif percent >= 40:
    print (f" you have recieved {percent:.2f}%, you definitely didn't pay attention in history class.")
elif percent <= 20:
    print (f" you have recieved {percent:.2f}%, are you even Canadian?")
# listAssign4.py
# Leen Saflo
# Determine if game of assasin is valid

targets = []
numPlays = 0
while True:
    target = input("Enter target assignment (enter 'end' once done): ")
    if target == "end":
        break
    targets.append(int(target))  

numPlays = len(targets)
pos = 0  # start from player 0
count = 0

while count < num_players:
    pos = targets[pos]  # move to the next person
    count += 1
    if count < num_players and pos == 0:  # if you get to 0 before visiting all players, it's invalid
        print("Invalid")
        break
else:
    # If you complete the loop and end at 0, it's valid
    if pos == 0:
        print("Valid")
    else:
        print("Invalid")