Session 3 - Loops Flashcards

Basics - Loops (20 cards)

1
Q

For Loop (2mins)

Print numbers 1 to 5 using For Loop
Output:
1
2
3
4
5

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

While Loop (2mins)

Print numbers 1 to 5 using while loop
Output:
1
2
3
4
5

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

For Loop (2mins)

Print each character in a string
Input 1: Hello

Output:
H
e
l
l
o

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For Loop (2mins)

Sum numbers from 1 to 10
Output:
Sum: 55

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

While Loop (2mins)

Countdown from 5 to 1 using while loop

Output:
5
4
3
2
1

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

For loop (2mins)

Print even numbers from 1 to 10
Input 1: I am learning Python today

Output:
2
4
6
8
10

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Reverse a String (2mins)

Ask the user to enter a word and print it reversed.

Input 1: hello

Output:
olleh

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

While loop (2mins)

Keep asking until user types “exit”
Input 1:
Type something: hello
Type something: again
Type something: exit

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

For Loop (2mins)

Count vowels in a word

Input 1: education

Output:
Number of vowels: 5

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

For Loop (2mins)

Print each word in a sentence
Input 1: Python is fun

Output:
Python
is
fun

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Join a List of Words into a Sentence (2mins)

Join words from a list into one space-separated string.

Input 1: [“Python”, “is”, “awesome”]

Output:
Python is awesome

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

While loop (2mins)

Sum numbers until total exceeds 100

Input 1:
Enter number: 30
Enter number: 50
Enter number: 25

Output:
Total: 105

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Summation (2mins)

Get the summation of numbers with a given step

Input 1:
Enter number: 5
Output:
Sum: 15

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fibonacci Sequence (3mins)

Print first N Fibonacci numbers

Input 1:
Enter how many Fibonacci numbers: 6

Output:
0 1 1 2 3 5

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Prime Number (3ins)

Ask the user for a number and check if it’s prime.

Input 1:
Enter a number: 7

Output:
7 is a prime number.

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Factorial Using a For Loop (3mins)

Ask the user for a number and compute the factorial using a loop.

Input 1:
Enter a number: 5

Output:
Factorial: 120

17
Q

Prime Numbers from 1 to 100 (4mins)

Print the prime numbers from 1 to 100
Output:
2 3 5 7 11 13 17 19 … 97

18
Q

Right-Angled Triangle (5mins)

Ask for a number of rows and print a triangle using *.
Input:
Enter number of rows: 4

Output:
*
**
***
**

19
Q

Pyramid (5mins)

Ask for number of rows and print a centered pyramid using *.
Input:
Enter number of rows: 4

Output:
*
*
***
**
*

20
Q

Diamond (5mins)

Ask the user for the number of rows for the top half of the diamond, then print a full diamond using *.
Input:
Enter number of rows: 4

Output:
*
*
***
**
*
****
**

*