Lesson 4/6High school~120 min
Mixed tasks
Tasks where loops, lists, functions and chance meet: a lottery, primes, perfect numbers, test scores and train passengers.
You can solve exercises without signing in; sign in and your progress is kept.
After this lesson you'll be able to:
- Split a program into functions with parameters and return values
- Use a function inside another function
- Combine loops, lists and conditions in one program
What you practise here
- Return values: return
- Integer division and remainder: // and %
- while loops
- for loops and range()
- Divisibility, primes, GCD
- Reading numbers from input
- The if statement
- Counting and summing in a loop
- List methods: append, pop, remove, …
- len, sum, min, max and sorted
+ 7
Short tasks that check you understand: multiple choice, predicting the output, finding the bug, completing code.
Start the exercisesReal programming tasks: write a program, run it and submit it to be checked, hidden tests included.
Start the challenges- Write a programLotteryElementary20 XP
- Write a programPrime numbersElementary20 XP
- Write a programMinimum, count and positionsElementary20 XP
- Write a programTest scoresElementary20 XP
- Write a programPerfect numbersElementary20 XP
- Write a programCoin tossBasic10 XP
- Write a programTrain passengersBasic10 XP
- Write a programLeap yearBasicOptional10 XP