Objectives

Students will be able to:

  • assign data from the keyboard to a variable
  • understand how to catch an error
  • understand that a programmer sometimes has to tell the computer what kind of data is being assigned
  • convert data from one type to another using built-in functions

Algorithms

An algorithm is a defined series of steps that must be followed in order to solve a problem.

Challenge

You have been hired by a popular restaurant chain to create a tip calculator program.

The program should allow the restaurant's customers to calculate the amount of tip to leave based on their bill amount and preferred tip percentage.

Requirements:

  1. Ask the user to enter the total bill amount.
  2. Ask the user to enter the tip percentage they would like to leave (e.g., 10, 15, 20).
  3. If valid inputs are provided, calculate and display the tip amount and the total amount (bill + tip)

Exception handling

  • The user enters a negative or zero value for the bill amount.
  • The user enters a non-numeric value for the bill or tip percentage.

Submission

Submit your .py file into Google Classroom.

Pseudocode

Often, program designers are amazing logical thinkers but are not experts on every programming language eg Java, Python, C++, C# etc

In big programming teams, program designers need to find a way to share a solution to a problem(s) with Java programmers, Python programmers, C++ programmers etc.

Pseudocode is often used. It looks like a programming language but it isn't really.

However, it can be understood by Java programmers who turn it into Java, Python programmers who turn it into Python, C++ programmers who turn it into....

Input and Exception Handling

 

Lucky Number Game

Enter a random number between 1 and 10. If you guess the lucky number, you win a prize!

Exception Handling

The above app demonstrates how a computer program has to handle user input.

What happens if you enter your name into the input box? Does the program crash? Or can it handle this awkward situation?

The program utilises exception (error) handling.

Open your IDE and follow the video to explore this concept in Python.

Task

Open your IDE and create a new file. Save it in your Python folder.

Copy the starter code into your IDE.

Complete the Worksheet as you follow the video.

Continue to the challenge!

The challenge is intended to activate your problem solving brain and attempt to use the strategies presented in the video.

You do not need to complete the challenge

But... you need to attempt to complete the challenge! This will help you to develop your coding skills.

Strategies for completing the Challenge successfully:

  • Share ideas with your classmates
  • Mess around with the code and see what works
  • Don't be afraid to start from scratch
  • Work with AI to develop a solution
  • Discuss problems you are having with your teacher

Tags

integratedsyntax development environment machine code translate type errorcompile