For and While loops

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/8

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

9 Terms

1
New cards

What is a while loop?

It allows you to repeat lines of code as long as a condition is true, conditionally

2
New cards

How can I use a while loop to print out numbers 1 to 10:

count = 1

while count < 11:

print(count)

count = count + 1

3
New cards

What is a for loop?

Used to repeat a sequence of steps a certain number of times.

4
New cards

What part of a for loop states the number of times that the indented code will be repeated

range

5
New cards

Write a for loop of a user saying the number of times something will be printed.

times = int(input(“Enter the number of times: “))

for count in range (times):

print (“This is the answer”)

6
New cards

How can I print out the value of the count variable?

for count in range (4):

print (count)

0

1

2

3

7
New cards

Write code specifying the start and end point for the count

for number in range (20,24):

print (number)

20

21

22

23

8
New cards

Write a code specifiying the start and finish and adding a step of 2

for number in range (1,10,2):

print (number)

1

3

5

7

9

9
New cards