๐Ÿ
๐Ÿ“ Python Fundamentals (Hands-On) ยท PY-101 ยท Assignments

Python Fundamentals (Hands-On) โ€” Assignments

Work each problem yourself first, then open the worked solution to check your thinking. This is where the course sticks.

๐Ÿ“ 5 problemsโœ๏ธ Worked solutions
Problem 1

Create several variables of different types and print combinations of them.

Show worked solution

A strong answer creates int, float, str and bool variables, uses them (arithmetic, string joining, a boolean), and shows understanding that = stores a value and the type determines valid operations. Bonus for using type() to check a value and for reassigning a variable (e.g. count = count + 1).

Problem 2

Write an if/elif/else that classifies an input (e.g. a number as negative/zero/positive).

Show worked solution

Good answers use correct comparison operators and == (not =) in conditions, proper indentation for each branch, and cover the cases with elif/else. Bonus for combining conditions with and/or and noting that == compares while = stores.

Problem 3

Write a for loop and a while loop that each do something useful, and explain when you'd use which.

Show worked solution

Strong answers show a for loop over a range or list and a while loop that repeats until a condition changes (with something inside that makes it able to stop), and explain the guideline: for when the count/collection is known, while for repeat-until. Bonus for noting range(n) is 0..n-1 and the infinite-loop pitfall.

Problem 4

Write a function with a parameter and a return value, then call it a few times.

Show worked solution

Good answers define a function that takes input(s) and returns a computed result, call it with different arguments, and use the returned value (store/print it). It should reflect the difference between return (hands a value back) and print (shows on screen), and the idea of decomposing problems into small functions.

Problem 5

Use a list and a dictionary to model some real data, and loop/look things up.

Show worked solution

Strong answers pick a list for an ordered sequence and a dict for labelled data (choosing appropriately), access a list item by index and a dict value by key, and loop over the list. Bonus for a list of dictionaries (a common real-world shape) and noting zero-based indexing.

More in this course

Course home → · Browse all courses →