Description | Implement your first interactive application. |
---|---|
Type | Hand-in assignment with oral explanation. |
Duration | About 1 working day. |
Progress points | 1.5 |
Learning goals |
|
Learning materials
Open the assignment template in Visual Studio Code by typing lms open
in the terminal. Next, install the Python Extension. You should now be able to run the provided Hello world! program by opening the hello.py
file and pressing F5
.
While studying the resources about Python below and in future lessons, it is a very good idea to experiment with what you're learning by writing small programs and running them. This tests your understanding of the things you're learning about, and helps you remember them.
If you experience hardship during the writing of your very first few python programs even after looking at the resources and asking other students, you can download the app Mimo (android playstore) where you can practice with python and set up reminders to train yourself a little with the concepts. Be mindful that the free period is only 14 days.
name = _____("What's your name? ")
name = "Pete"
if name == "John":
print("x")
else:
print("y")
Assignment
Considering that you're a fresh student just starting out on a degree programme, there's only one possible application we could possibly have you built as your first real programming assignment. Yes, a responsible alcohol use advisor app, of course!
You'll be creating the application step-by-step, but here is a demo of how the final product should work:
Note: If you already have experience programming in another language, Python may feel weird at first. It has its own conventions, like snake_case
for variables and functions (instead of camelCase
or TitleCase
), not using (
braces)
around if
conditions, and not using semicolons;
after each statement. As a multi-lingual programmer, you should get used to learning and sticking to the conventions of the programming environment you're currently working in.
Objective #1: Welcome!1.2 points
All great things start with a small first step.
Within the alcohol.py
file, create a program that just prints the following output:
*** Responsible alcohol use calculator ***
Notice the empty lines before and after the title.
Hint: You'll require the use of print
and a "string"
. Note that strings can be empty: ""
.
Objective #2: Who's this?1.2 points
Extend your program to ask the user's name, and to say hi to her or him. The output should look something like this:
*** Responsible alcohol use calculator ***
What's you name? Frank
Hi Frank
When the user enters a name different than Frank that name should of course be used to say hi to.
Hint: You'll require the use of input
and a variable. Make sure to give your variable a fitting name. Giving your variables a meaningful name helps you understand what your program is doing when it's growing bigger.
Remember that print
can have multiple arguments, separated by commas, to output multiple things on one line.
Objective #3: Gender?1.2 points
Extend your program to ask the user's gender. Print a womanly message when the user enters 'female' and print a manly message when the user enters 'male'. For now, don't do anything when the user enters something else.
Hint: You'll require the use of if
and the ==
operator (for comparison).
print(1==1)
Objective #4: Drinks?1.2 points
Have your program ask for the weekly number of alcoholic beverages the user drinks on average. Then show how many beverages that are per year.
*** Responsible alcohol use calculator ***
What's you name? Frank
Hi Frank!
What's your gender? [female/male] male
Men are awesome!
How many alcoholic beverage do you drink on average per week? 10
That's 520 per year!
For now, your application may just crash (quit with an error message) when the user enters anything other than a whole number.
Hint: You'll require the int
function to convert a string to an integer, in order to do the *
calculation.
Objective #5: A word of advice1.2 points
- When the user drinks 0 alcoholic beverages per week, output the text
Healthy choice, <NAME>!
. - Otherwise, if the user drinks less than 7 alcoholic beverages per week, output the text
You'll probably be okay, <NAME>!
. - Otherwise output the text
Drinking less would be a healthier choice, <NAME>!
.
Hint: You'll require the use of elif
and else
.
Objective #6: Gender-specific advice1.2 points
Instead of just saying Drinking less would be a healthier choice
, we want to add some more stringent advice, but the norms are based on the gender of the drinker.
- For women, the norm for excessive drinking is 14 beverages per week.
- For men, it's 21 beverages per week.
Based on that:
- When the user doesn't drink more than the norm, we'll stick to the messages from the previous assignment:
Drinking less would be a healthier choice
. - Otherwise, when the user doesn't drink more than twice the norm, we want to output
You're an excessive drinker, <NAME>.
That's not healthy.
. - If the user drinks even more, we want to output
You're a really heavy drinker, <NAME>.
That's very unhealthy.
Change your ways!
Hint: Write the norm for the selected gender to a (fittingly named) variable, assigning it the appropriate value in the if
-block for gender. Next, you can use that variable to extend the if/elif/else
construct from the previous objective.
Objective #7: Error handling1.2 points
Users rarely behave the way we programmers think they should. They've been know to type the biggest nonsense into your carefully crafted application! It's up to us programmers to deal with all of that.
In each of these cases, the program should display a respectful error message and then stop the program:
- When the user leaves the name field empty.
- When the user enters a gender other than
male
orfemale
. - When the user enters a beverage count that is not a whole number (integer).
After doing this, your program should be unbreakable (semi-Dutch: hufterproof).
Hints:
- You can call the
exit()
function to stop your Python program early (before it reaches the end). - For the last check, you can use
try
andexcept
to catch the error thrown by theint
function when you pass it a string that does not contain a proper integer number. Try to keep the code block you surround withtry
andexcept
as small as possible.
Objective #8: PunctualityMUST
Attention to detail is very important in your way to become an awesome developer. Make sure that the output of your program:
- Closely matches the provided video and example outputs.
- Contains no spelling errors. Hint: Install the Code Spell Checker extension (by streetsidesoftware) for Visual Studio Code. Just take a minute to do this. Really.
- Uses correct and easy to understand messages.
- Uses capital letters, white spaces and punctuation in all the right places.
Objective #9: Code quality+ 0.4 points- 1.4 points
Your code should be easy to understand, using the simplest possible logic, sensible variable names, empty lines to separate distinct parts of the program and consistent use of whitespace.
Rubrics mapping and grading
#1 | #2 | #3 | #4 | #5 | #6 | #7 | #9 | - | Σ | |
---|---|---|---|---|---|---|---|---|---|---|
Declare and assignment variables. | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.64 | -0.48 | 3.1 |
Output text and read user input. | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.64 | -0.48 | 3.1 |
Give variables and functions concise but descriptive names. | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.64 | -0.48 | 3.1 |
Base grade. | 1.00 | 1.0 | ||||||||
Σ | 1.28 | 1.28 | 1.28 | 1.28 | 1.28 | 1.28 | 1.28 | 1.92 | -0.44 | 10.4 |
Learning materials
Open the assignment template in Visual Studio Code by typing lms open
in the terminal. Next, install the Python Extension. You should now be able to run the provided Hello world! program by opening the hello.py
file and pressing F5
.
While studying the resources about Python below and in future lessons, it is a very good idea to experiment with what you're learning by writing small programs and running them. This tests your understanding of the things you're learning about, and helps you remember them.
If you experience hardship during the writing of your very first few python programs even after looking at the resources and asking other students, you can download the app Mimo (android playstore) where you can practice with python and set up reminders to train yourself a little with the concepts. Be mindful that the free period is only 14 days.
name = _____("What's your name? ")
name = "Pete"
if name == "John":
print("x")
else:
print("y")
Assignment
This application will help you calculate interest over your accrued money in your bank.
You'll be creating the application step-by-step, but here is a demo of how the final product should work:
Note: If you already have experience programming in another language, Python may feel weird at first. It has its own conventions, like snake_case
for variables and functions (instead of camelCase
or TitleCase
), not using (
braces)
around if
conditions, and not using semicolons;
after each statement. As a multi-lingual programmer, you should get used to learning and sticking to the conventions of the programming environment you're currently working in.
Objective #1: Welcome!1.2 points
All great things start with a small first step.
Within a new interest.py
file, create a program that just prints the following output:
**** Welcome to the interest calculator! *****
Notice the empty lines before and after the title.
Hint: You'll require the use of print
and a "string"
. Note that strings can be empty: ""
.
Objective #2: Who's this?1.2 points
Extend your program to ask the user's name, and to say hi to her or him. The output should look something like this:
*** **** Welcome to the interest calculator! ***** ***
Please input your name: luuk
Hi Luuk!
When the user enters a name different than luuk that name should of course be used to say hi to. Notice that the user inputted all lowercase yet the hi message displays the name with a capital letter. There might be a convenient python function for this ;)
Hint: You'll require the use of input
and a variable. Make sure to give your variable a fitting name. Giving your variables a meaningful name helps you understand what your program is doing when it's growing bigger.
Remember the f-strings that allow you to input text as well as variables in one single line.
Objective #3: Money?1.2 points
Extend your program to ask the user how much money they want to leave at the bank. Make sure that the input is real number. So no "text" is allowed!
Hint: You'll maybe want to make use of the .isdigit() function.
print(1==1)
Objective #4: Years?1.2 points
Ask the user how many years they would like to store their money with the bank. Make sure these are a true number and exit with an message when it's not a valid year.
Objective #5: Calculating interest (simple)1.2 points
Now the interesting part. If the user has their money with our bank for less than 10 years, we'd give them 2.5% interest per year. If they leave their money with us between 10 and 15 years with us we'd give them 3.1% per year and if they commit to us for longer than 15 years we will give them 5% per year.
**** Welcome to the interest calculator! *****
Please input your name: luuk
Hi Luuk
Please enter the amount of money (in whole dollars) you'd like to accrued interest on: 1000
For how many years do you want to calculate ahead?: 15
after 15 years you'd have: 1075.0 dollars!
hint to calculate behind the decimal you might want to cast the number to a float before or during the calculation
Objective #6: Advanced interest 11.2 points
Instead of just calculating crude interest on the whole amount each year, we want to give our users interest every month for every year that they are with us. Update your functions so that we calculate interest per month instead of per year. Make sure that the amount per year doesn't change too much from what it is now. We still don't want to give users way more than ~2.5% per year. However you will see that if you accrued it per month, they will be making a bit more money.
Objective #7: Error handling1.2 points
Users rarely behave the way we programmers think they should. They've been know to type the biggest nonsense into your carefully crafted application! It's up to us programmers to deal with all of that.
In each of these cases, the program should display a respectful error message and then stop the program:
- When the user leaves the name field empty.
- When the user enters an starting amount any other than a round numbers (no decimals)
- When the user enters an amount of years any other than round numbers (no half years are allowed)
After doing this, your program should be unbreakable (semi-Dutch: hufterproof).
Hints:
- You can call the
exit()
function to stop your Python program early (before it reaches the end). - For the last check, you can use
try
andexcept
to catch the error thrown by theint
function when you pass it a string that does not contain a proper integer number. Try to keep the code block you surround withtry
andexcept
as small as possible.
Objective #8: PunctualityMUST
Attention to detail is very important in your way to become an awesome developer. Make sure that the output of your program:
- Closely matches the provided video and example outputs.
- Contains no spelling errors. Hint: Install the Code Spell Checker extension (by streetsidesoftware) for Visual Studio Code. Just take a minute to do this. Really.
- Uses correct and easy to understand messages.
- Uses capital letters, white spaces and punctuation in all the right places.
Objective #9: Code quality+ 0.4 points- 1.4 points
Your code should be easy to understand, using the simplest possible logic, sensible variable names, empty lines to separate distinct parts of the program and consistent use of whitespace.
Rubrics mapping and grading
#1 | #2 | #3 | #4 | #5 | #6 | #7 | #9 | - | Σ | |
---|---|---|---|---|---|---|---|---|---|---|
Declare and assignment variables. | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.64 | -0.48 | 3.1 |
Output text and read user input. | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.64 | -0.48 | 3.1 |
Give variables and functions concise but descriptive names. | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.42 | 0.64 | -0.48 | 3.1 |
Base grade. | 1.00 | 1.0 | ||||||||
Σ | 1.28 | 1.28 | 1.28 | 1.28 | 1.28 | 1.28 | 1.28 | 1.92 | -0.44 | 10.4 |