# Arup Guha
# 4/17/2020
# Written for COP 2930 - showing sample questions in prep for Final Exam Part A.
# This runs, but most of the code has intentional errors, which the questions
# are about

# Segment of code #1

player1 = []
print("Input player 1's five scores")
for i in range(5):
    player1.append(int(input("")))

player2 = []
print("Input player 2's five scores")
for j in range(5):
    player2.append(int(input("")))

''' The issue is that the programmer might not understand that i
    is not storing anything valuable, so it can be reused in the
    second loop.
'''

# Segment of code #2 (Trying to print out mult table of products 1 through 10.

for i in range(10):
    for i in range(10):
        print(i*i, end = " ")
    print()

''' What are the problems with this code?
    1. Second loop (inner) needs a DIFFERENT variable.
    2. If we change inner loop to j, i*j
    3. Even with j change, 0 through 9 table.

    Two ways to fix the range of products.
    1. range(1,11), range(1,11)
    2. (i+1)*(j+1)
'''

# Segment of code #3: trying to add 1 to 100

for i in range(1, 101):
    total = 0
    total = total + i
print(total)

''' Why doesn't this work?
    total needs to be defined and set to 0 BEFORE the loop.
    The way it's written, it gets reset to 0 every time, so nothing gets
    added.
'''

#Segment of code #4: Test Average Question

total = 0
print("Please enter your five test scores.")
for i in range(5):
    total += int(input(""))

print("Your average was",total//5)

''' Why is this slightly wrong? How do you fix it?
    We are doing integer division so the fraction gets cut off.
    To fix, use a single forward slash
'''

# Give me three examples of when it's useful to use integer division.

''' 1. Chicken nuggets - these are whole, so if you want to know how many
       chicken nuggets each person in a group will get if split equally,
       we would use integer division (unless people split nuggets)
    2. Material to build something 10 x 10 floor tiles are 3 x 3 how many
       tiles do I need to buy?
    3. Convert inches to feet and inches -> int division gives whole # of feet
'''

# Give me an example of a use of a dictionary in Python.

''' 1. Storing IDs to student names (names -> ID, ID -> names)
    2. Payroll (employeeID -> pay)
    3. Banking info (name -> CC#)
'''

# Segment of Code #5 - Prime Sieve
''' Next example - goal is to print a list of prime numbers from 2 to
    100. The algorithm we are trying to implement works like this.

    1. Assume everything from 2 to 100 is prime, put a true in a all
       indexes in a list.
    2. But we know that 2 times a prime isn't prime, 3 times a prime
       isn't prime, and so forth. So, for each number, i, find all
       of its multiples 2i, 3i, 4i, 5i, ... and mark them False, meaning
       they are not prime.

       2  3  4  5  6  7  8  9  10  11  12  13  14 15 16 17 18 19 20
       T  T  T  T  T  T  T  T  T   T   T   T   T  T  T  T  T  T  T
       T  T  F  T  F  T  F  T  F   T   F   T   F  T  F  T  F  T  F
       T  T  F  T  F  T  F  F  F   T   F   T   F  F  F  T  F  T  F
       T  T  F  T  F  T  F  F  F   T   F   T   F  F  F  T  F  T  F
       T  T  F  T  F  T  F  F  F   T   F   T   F  F  F  T  F  T  F

       What is wrong with the implemetation of this algorithm shown
       below?
'''

isprime = []
for i in range(101):
    isprime.append(True)

for i in range(2,101):
    for j in range(2*i, 101):
        isprime[j] = False

for i in range(2, 101):
    if isprime[i]:
        print(i, end=" ")
print()
    
# There is one tiny thing wrong in this implementation, what is it?
# How do you fix it?
# What is wrong is that the j loop doesn't jump at all. It makes
# everything from 2*i on false.
# Fix, for j in range(2*i, 101, i):





    

                   
                   

                   
