1. Define an Iteration Iteration is a sequence of code being repeated until a specific end result is achieved.
  2. Make your own example of an iteration with at least 4 steps and a stopping condition(Similar to mine that I did) When you are buying a flight ticket, you are gonna check if the price fit. If not, you will do the loop of continuous searching tickets until you find the best price. Then you are checking if the time fits, if not, search different flight until you find the best fit.
  3. Program a simple iteration.
bid1 = int(input("What is your initial amount"))
while bid1 < 100:
    print(bid1, "is not enought")
    bid1 = int(input("try another amount"))
    if bid1 >= 100:
        print("The amount", bid1, "is enough")
2 is not enought
34 is not enought
18 is not enought
The amount 100 is enough
  1. What is an iteration statement, in your own words? Iteration statement cause statement to run more times and break when it achieve the ideal result.
  2. Create a descending list of numbers using for loop

  3. Using while loop, make a list of numbers which will form an output of 3,16,29,42,55,68,81

myList = [4, 2, 7, 3, 9, 0]
myList.sort(reverse = True)
print((myList))
[9, 7, 4, 3, 2, 0]
i = 3
while i <= 81:
  print(i)
  i += 13
3
16
29
42
55
68
81

Find the minimum in a list

nums = ["10", "15", "20", "25", "30", "35"]
print(min(nums))
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 inserted into a list at index i?
index()
Correct!
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 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!