Hacks 3.8.1

Iteration: An Iteration is a loop in an algorithm that repeats until a certain condition is met (or if there is a given amount of times that needs to be repeated).

for i in range(10):
    print(i)
    if i == 7:
        break
0
1
2
3
4
5
6
7

Hacks 3.8.2

An iteration statement is something that makes a statement to be ran zero or more times that can be affected by any condition that affects the loop.

number = [1, 10 , 20, 69, 12, 56, 190, 2001, 19983, 2, 3, 6, 72]
print('Regular list: ', number)
for i in number:
    number.sort(reverse = True)
print('Sorted list:', number)
Regular list:  [1, 10, 20, 69, 12, 56, 190, 2001, 19983, 2, 3, 6, 72]
Sorted list: [19983, 2001, 190, 72, 69, 56, 20, 12, 10, 6, 3, 2, 1]
# for item in numbers:
#     print(item)

for item in range(3,82,13):
    print(item)
3
16
29
42
55
68
81

3.8.3

No Hacks given on presentation

3.10 Hacks

nums = [10, 15, 20, 25, 30, 35]
min = 20
for i in nums:
    if i < min:
        min = i
        print(min)
10
import getpass, sys
import random

def ask_question (question, answer):

    print(question)
    ans = input(question)
    print(ans)
   
    if ans == answer:
        print("Correct!")
        return 1

    else:
        print("Wrong")
        return 0

question_list = ["What allows a value to be inserted into a list at index i?" , "What allows an element at index i to be deleted from a list?" , "What returns the number of elements currently in a specific list?" , "What allows a value to be added at the end of a list?"]
answer_list = ["index()", "remove()", "length()" , "append()"]

# Set points to 0 at the start of the quiz
points = 0

# If the length of the quiz is greater than 0, then random questions will be chosen from the "question_list" set
while len(question_list) > 0:
    index = random.randint(0, len(question_list) - 1)
    
# The points system where a point is rewarded for each correct answer    
    points = points + ask_question(question_list[index], answer_list[index])
    
# If a question or answer has already been used, then it shall be deleted    
    del question_list[index]
    del answer_list[index]

# Calculating score using the points system and dividing it by the total number of questions (6)
score = (points / 4)

# Calculating the percentage of correct answers by multiplying the score by 100
percent = (score * 100)

# Printing the percentage, and formatting the percentage in a way where two decimals can be shown (through "{:.2f}")
print("{:.2f}".format(percent) + "%")

# Adding final remarks based upon the users given scores
if points >= 5:
         print("Your total score is: ", points, "out of 4. Amazing job!")

elif points == 4:
         print("Your total score is: ", points, "out of 4. Not too bad, keep on studying! " )

else:
         print("Your total score is: ", points, "out of 4. Its alright, better luck next time!")
What allows a value to be added at the end of a list?
append()
Correct!
What returns the number of elements currently in a specific list?
length()
Correct!
What allows a value to be inserted into a list at index i?
index()
Correct!
What allows an element at index i to be deleted from a list?
remove()
Correct!
100.00%
Your total score is:  4 out of 4. Not too bad, keep on studying! 

Extra Credit

grades = [100, 98, 56, 72, 60, 88, 92, 92, 100, 81]
students = 21
passing = 75
print("Original grade list: ", grades)
while len(grades) < students:
    item = int(input("Enter another student's grade"))
    grades.append(item)
grades.sort()
print("Updated List of Grades ", grades)
for item in grades:
    if item >= 75:
        print("eligible for credit")
    elif item < 75:
        print("ineligible for credit")

# I essentially have some grades that I have already corrected, but I have 21 students. I use the while function to make sure that 
# I get the rest of the remaining tests needed to be input, where it will then stop asking me for more grades to put in once i get everyone.
# After that, I ask the code to sort the list
# Additionally, after getting the grades for each student, I need it to sort the grades from least to greatest
# Thats where I use the if and elif for whether they have enough for credit or not.
    
Original grade list:  [100, 98, 56, 72, 60, 88, 92, 92, 100, 81]
Updated List of Grades  [12, 34, 56, 56, 60, 67, 72, 76, 78, 81, 88, 89, 90, 90, 92, 92, 98, 98, 100, 100, 100]
ineligible for credit
ineligible for credit
ineligible for credit
ineligible for credit
ineligible for credit
ineligible for credit
ineligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit
eligible for credit

I essentially have some grades that I have already corrected, but I have 21 students. I use the while function to make sure that I get the rest of the remaining tests needed to be input, where it will then stop asking me for more grades to put in once i get everyone. After that, I ask the code to sort the list Additionally, after getting the grades for each student, I need it to sort the grades from least to greatest Thats where I use the if and elif for whether they have enough for credit or not.