Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
These problems follow 4.1 Defining functions and 4.2 Scope and return values. Use def, parameters, and return (and local variables) instead of one long script. You can still use input, loops, and lists where it helps.
Lessons: 4.1 Defining functions · 4.2 Scope and return values
Navigation
Tutorials: Tutorial 4.1 · Tutorial 4.2
def, parameters, and printwelcome(name) prints a one-line greeting using the parameter.divider() prints a fixed line of characters (no parameters).discounted_price(price, percent_off) returns the sale price.ticket_total(adults, children) returns total cost from counts.total_minutes(hours, minutes) returns one integer.can_ride(height_cm) returns whether height is at least 120 cm.is_vowel(ch) returns True for a single vowel letter (ignore case).passed(mark) returns True if the mark is 40 or more.factorial(n) returns n! for n between 1 and 10 (use a loop, not math.factorial).sum_to(n) returns 1 + 2 + … + n for n ≥ 1.count_divisors(n) returns how many integers from 1 to n divide n evenly.ask_addition() asks one question and returns True if correct; main() runs three rounds and prints the score.Solutions: e.g. Task 1 solution.