0% found this document useful (0 votes)
12 views3 pages

Topic 2 Homework Questions

The document outlines homework assignments for a Python programming course focused on lists and loops. Students are tasked with creating functions, manipulating lists, and using loops to solve various problems, including a simplified Hangman game. The assignments emphasize understanding and experimenting with Python concepts through practical coding exercises.

Uploaded by

James SI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Topic 2 Homework Questions

The document outlines homework assignments for a Python programming course focused on lists and loops. Students are tasked with creating functions, manipulating lists, and using loops to solve various problems, including a simplified Hangman game. The assignments emphasize understanding and experimenting with Python concepts through practical coding exercises.

Uploaded by

James SI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Topic 2: Lists and Loops

Homework Questions
Python Programming for Economics
Dr. Marcus Roel
Spring 2024, UNNC
Homework
standard-homework: go over our examples from the lecture and (1) understand them,
and (2) vary them slightly to see if you really understand them.

Arguments and Keywords


Write a function that can multiply, 3 values with one another, e.g., xyz. Can you you
use a default value to improve its flexibility.
Try to call this function with a different number of arguments. (Whether this
works will depend on your code.)
Write a function that calculates(a + 2b)
c
.
Call this function using positional arguments as well as keyword arguments.
Revisit the function is_bigger_than from homework 1. Rewrite this function by
making the print-out (e.g., print(x, 'is bigger than', y) ) optional and
instead return True/False for the two cases. Hint: use third parameter with a default-
value that determines the printing.

while
Use a while-loop to loop over each persion in the dataset below and print their
name, age, and hobby (maybe nicely formatted) in the dataset dataset =
[['Marcus', 34, 'Running'], ['Lars', 37, 'Play Guitar'],
['Johannes', 45, 'Cycling']]

hint: use len(dataset) to get the number of entries in the (highest level) list.

lists
Create a list (using range) with items
1, 2, ..., 8
5, 6, 7
2, 4, 6, 8, 10
-3, -6, -9
Using the above lists, try to access a single particular value as well as multiple
values using slices
experiment with the other list functions such as append(), pop(), index(), and
remove().
Create a list of lists, where the second dimension lists have the following values
[1,2,3], [4,5,6], and [7,8,9]

Fun with lists


Create a function that prints a
square of dimensions 3x3
a triangle (you can choose the particular shape)
a christmas tree
hint: use some form of loops (there are many solutions to this problem)
Hints
Once you successfully drawn the above, go back to your code and see if you can
turn these into a general function

Pretend Application lists


Suppose you have a list of simple numbers collected from answers to survey
questions
Question: "how many job applications do you plan to do daily"
Some people actually claimed 10 000 or 500, etc. (that did not match their
subsequent real life choices)
Write function that takes as an input a list of numbers and simply changes their
value to something sensible, say 20.
note, don't manipulate the original list (bad practise) but store values to a new
list and return it.
note, for real research, is usually better to treat items as 'missing' (and omit
them from analysis) instead of arbitrarily changing them.
the best way to do that would be to set it to, say, -1, if all other numbers are
positive

Big Homework Question


1. Code the "Simplified" Hangman game!
Guess a single number (among 1,...,10) in x-tries
2. Code the Full Hangman game! (optional - hard)
For these hard problems, generally make your life simple by separating out the
problem into small pieces
set the 'secret number/word' yourself and pretend that you don't know it :)
start with simplified version of each piece
test each before you combine them
try as best as you can. If they are too hard, feel free to skip them
In [ ]:

You might also like