Chapter 2 Coding Exercises
This is the complete set of exercises to assist you in working through Chapter Two. Some of these exercises may also appear in Coding Workshops.
Exercise 1a
Make your own hello world program in your Playground:
- Add a new file
- Call it
ABC_hello_world.yml(Replace ABC with your initials) - Create a single mandatory question block that displays 'Hello world' (base your code on
hello_world.ymlin the video)./references/ex1a_references.mdx
Exercise 1b
Modify your Exercise 1a code to add a question block to ask for your name.
Exercise 1c
Modify your Exercise 1b code to:
- add exit and restart buttons;
- re-format your question block so that the question is asked in the
subquestiontag; - Diplay the user's name in bold; and
- when pressing Exit your app should send you to the Flinders University BGL website.
Add a second question that asks for the user's age. Display the result in the app's output.
Exercise 1d
Modify your Exercise 1c code to:
- add a question to ask for your salutation;
- replace the name question with two fields for a first and last name;
- display the output in a table. The table should contain two rows with:
- the first row containing the name. It should display the full name (ie: join the salutation, first and last names together); and
- the second row shoudl contain the age.
Exercise 1e
Create a program which does the following:
- ask for the user's name and for the user's age;
- If the user is under 18 then display:
Hello name, you are just a child!
- If the user is over 18 but less than 50 then display:
Hello name, you are an adult.
- If the user is over 65 then display:
Hello name, you are an adult and are eligible for the age pension.
Use if statements and elif to manage testing for the different age ranges.
Exercise 1f
Extend your code from Exercise 1e to do the following:
- ask for the user's annual income;
- the term 'annual income' should have a pop-up that defines what annual income means;
- If the user inputs an income, it should be displayed in the final screen as currency
(hint: use the
currency()function) - If the user inputs an income of $0, then the text 'you do not earn an income' should be displayed in the final screen.
Hello Hansel Forrest, you are an adult and your annual income is $45,000.
Exercise 1g
Extend your code from Exercise 1f to do the following:
- ask if the user has a partner;
- if the user has a partner, then ask for the partner's name and partner's income;
- display the total household income (which is the sum of the two incomes) on the final screen;
- display the average household income on the final screen
Hello Hansel Forrest. Your partner's name is Gretel Forrest Your annual income is $45,000 and Gretel Forrest's annual income is $30,000 Your total household income is $75,000 Your average household income is $37,500
- You can use
show ifto display the partner details if the user has a partner - Remember to account for the case when the user does not have a partner when you create the total household and average household incomes - have another look at Video C1.06
Exercise 1h
Create an app which assesses a candidate on whether they can stand for Parliament. You should base your app on the following flowchart.