Python practice: Definite Loops with for and range()
Chapter 7 · 8 questions · included in full access
Question 1 · easy
Loop with range(5)
Solve it in your browserUse a
forloop withrange(5)to print numbers0to4on separate lines:Question 2 · easy
Sum of numbers 1 to 10
Solve it in your browserCalculate the sum of numbers from 1 to 10 using a
forloop withrange(1, 11)and an accumulatortotal = 0. Printtotal:Question 3 · easy
Multiples of 5 with step
Solve it in your browserUse
range(10, 35, 5)to print numbers10,15,20,25,30on separate lines:Question 4 · easy
Iterate through string characters
Solve it in your browserLoop through the string
"ACME"with aforloop and print each character in uppercase on a separate line:Question 5 · easy
Indexed loop with enumerate
Solve it in your browserGiven
reps = ["Asha", "Ravi", "Priya"], useenumerate(reps, start=1)to print each rep formatted asf"#{rank}: {rep}":Question 6 · easy
Accumulate order revenues
Solve it in your browserGiven
orders = [1200, 3400, 850, 4100], compute total revenue using a loop and printtotal:Question 7 · medium
Count positive balances
Solve it in your browserGiven
balances = [100, -50, 200, 0, 350, -10], count how many accounts have balance > 0 and printcount:Question 8 · medium
Find maximum transaction
Solve it in your browserGiven
sales = [450, 1200, 310, 890, 750], find the highest sale using a loop and variablepeak = 0. Printpeak:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing