Session 3 - Loops Flashcards
Basics - Loops (20 cards)
For Loop (2mins)
Print numbers 1 to 5 using For Loop
Output:
1
2
3
4
5
A
While Loop (2mins)
Print numbers 1 to 5 using while loop
Output:
1
2
3
4
5
A
For Loop (2mins)
Print each character in a string
Input 1: Hello
Output:
H
e
l
l
o
For Loop (2mins)
Sum numbers from 1 to 10
Output:
Sum: 55
A
While Loop (2mins)
Countdown from 5 to 1 using while loop
Output:
5
4
3
2
1
A
For loop (2mins)
Print even numbers from 1 to 10
Input 1: I am learning Python today
Output:
2
4
6
8
10
A
Reverse a String (2mins)
Ask the user to enter a word and print it reversed.
Input 1: hello
Output:
olleh
A
While loop (2mins)
Keep asking until user types “exit”
Input 1:
Type something: hello
Type something: again
Type something: exit
A
For Loop (2mins)
Count vowels in a word
Input 1: education
Output:
Number of vowels: 5
A
For Loop (2mins)
Print each word in a sentence
Input 1: Python is fun
Output:
Python
is
fun
A
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
While loop (2mins)
Sum numbers until total exceeds 100
Input 1:
Enter number: 30
Enter number: 50
Enter number: 25
Output:
Total: 105
A
Summation (2mins)
Get the summation of numbers with a given step
Input 1:
Enter number: 5
Output:
Sum: 15
A
Fibonacci Sequence (3mins)
Print first N Fibonacci numbers
Input 1:
Enter how many Fibonacci numbers: 6
Output:
0 1 1 2 3 5
A
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
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
A
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
A
Right-Angled Triangle (5mins)
Ask for a number of rows and print a triangle using *.
Input:
Enter number of rows: 4
Output:
*
**
***
**
A
Pyramid (5mins)
Ask for number of rows and print a centered pyramid using *.
Input:
Enter number of rows: 4
Output:
*
*
***
***
A
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:
*
*
***
***
****
**
*
A