Iteration Flashcards
1
Q
Count Controlled Iteration:
- Ask the user to enter a number to count from 0 up to.
- The program counts up to that number and stops at that number.
- This means the code within the loop will execute this exact number of times:
A
- number = int(input(“Please enter a number to count up to - “))
- for i in range (0, number, 1):
- print(i)
2
Q
Condition Controlled Iteration:
- We are asking the user to enter a test score
between 0 and 50 for a test.
- If the user enters anything outside of this range (e.g. -4, 51 etc.) then the program will repeat the code, requesting the user re-enter the score.
- This code will repeat until the score entered meets the criteria of being between 0 and 50:
A
- score = 0
- score = int(input(“Enter a test score between 0 and 50 - “))
- while score < 0 or score > 50:
- print(“Invalid score entered”)
- score = int(input(“Enter a test score between 0 and 50 - “))