Search this site
Embedded Files
Software Engineering
  • Home
  • Preliminary
    • Programming Fundamentals
      • Project 0 - Intro
        • Software Development Process
        • Waterfall Vs Agile
      • Project 1 - Mad Libs
        • Lab 1 - Hello World
        • Lab 2 - Hello, name
        • Lab 3 - Hello, full name
        • Lab 4 - Split String
      • Project 2 - Temperature Converter
        • Lab 1 - Numbers
        • Lab 2 - Number Operations
        • Lab 3 - Formatting Numbers
        • Lab 4 - Conditionals
      • Project 3 - Guessing Game
        • Lab 1 - While Loops
        • Lab 2 - For Loops
        • Lab 3 - Input Validation
        • Lab 4 - Random
      • Project 4 - Dice Roller
        • Lab 1 - Functions
        • Lab 2 - Parameters and Arguments
        • Lab 3 - Try / Except
      • Project 5 - To Do List
        • Lab 1 - Lists
        • Lab 2 - Advanced List Features
        • Lab 3 - Errors
      • Project 6 - Shopping List
        • Lab 1 - Dictionaries
        • Lab 2 - Lists and Dictionaries
        • Lab 3 - Data Dictionaries
      • Project 7 - Tic Tac Toe
        • Lab 1 - Intro to Connect Four
        • Lab 2 - IPO Diagram and Screen Design
        • Lab 3 - Structure Chart and Modular Design
        • Lab 4 - Starting Development & Basic Gameplay
        • Lab 5 - Core Game Mechanics
        • Lab 6 - Win and Draw Conditions
      • Project 8 - Contacts
    • Object Oriented Programming
      • Project 9 - Contacts (OOP)
        • Lab 1 - Paradigms
        • Lab 2 - Classes
        • Lab 3 - Methods
        • Lab 4 - Contacts Manager
      • Project 10 - Animal Kingdom
        • Lab 1 - Generalisation & Inheritance
        • Lab 2 - Polymorphism
        • Lab 3 - Zoo Management System
      • Project 11 - Shapes & Geometry
      • Project 12 - Inventory System
        • Lab 1 - Encapsulation Revisited
        • Lab 2 - The Facade Pattern
        • Lab 3 - User Interface
      • Project 13 - Banking System
      • Project 14 - Library System
        • Lab 1 - Basic Text IO
        • Lab 2 - Introduction to JSON
        • Lab 3 - Library System
      • Project 15 - D&D Character Creator
    • Programming Mechatronics
      • Intro to Mechatronics
        • Applications
        • Components
        • Microbit
      • Computer Architecture
        • Microcontrollers vs CPUs
        • Instruction Sets and Opcodes
        • Registers and Real-Time Systems
      • Sensors and Data
        • Sensor Basics
        • Compass
        • Thermostat
        • Mapping and Clamping
        • Night Light
        • Parking Sensors
      • Actuators and Mechanics
        • Actuator Basics
        • Actuator Selection
        • DC Motors
        • Servos
        • Grippers
        • Pick and Place
      • Control Systems
        • Intro to Control Systems
        • Bang-Bang Control
        • PID Control
        • Autonomous Control
      • Power, Electrical and Wiring
        • Power Requirements
        • Electrical and Wiring
  • HSC
    • Programming For The Web
      • Command Line Basics
      • HTML
        • Task 1 - Basic Page
        • Task 2 - Contact Form
        • HTML Quiz
      • CSS
        • Task 1 - Style Basic Page
        • Task 2 - Style Contact Form
        • CSS Quiz
      • Bootstrap
        • Task 1 - Basic Bootstrap Page
        • Task 2 - Bootstrap Contact Form
        • Bootstrap Quiz
      • Flask
        • Task 1 - Installation
        • Task 2 - Routes
        • Task 3 - Templates
        • Task 4 - Flask Contact Form
        • Flask Quiz
      • SQLite
        • Task 1 - SQL Basics
        • Task 2 - SQLite Basics
        • Task 3 - SQLite and Flask
        • Task 4 - Object-Relational Mapping
        • SQLite Quiz
      • The Internet
        • Data Transfer
        • Web Protocols
        • Dev Tools
        • Securing the Web
        • Big Data
        • Internet Quiz
      • PWA Assessment Task
        • Progressive Wep Apps
        • Project Setup and Planning
        • Backend Development with Flask
        • User Interface and Design
        • Application Features
        • PWA Features
    • Secure Software Architecture
      • Introduction
        • Unsecure PWA
        • Vulnerabilities
        • Cybersecurity Concepts
        • Case Studies
      • Benefits
        • Data Protection
        • Confidentiality, Integrity, Availability
        • Minimising Cyber Attacks and Vulnerabilities
        • Authentication, Authorisation, Accountability
      • Software Development Steps
      • Influence of End Users
      • Security Features Incorporated Into Software
      • Cryptography and Sandboxing
      • Testing and Evaluating Security and Resilience
        • SQL Injection
        • Cross Site Scripting
        • Broken Authentication
        • Cross Site Request Forgery
      • Design, Develop and Implement Secure Code
    • Software Automation
      • Introduction
      • Labs
        • Numpy
        • Matplotlib
        • Scikit - Linear Regression
        • Scikit - Logistic Regression
        • Scikit - KNN
        • Scikit - Polynomial Regression
      • Training Models
        • Supervised Learning
        • Unsupervised Learning
        • Semi-Supervised Learning
        • Reinforcement Learning
      • Applications of Key ML Algorithms
      • Decision Trees and Neural Networks
        • Decision Trees
        • Neural Networks
      • Machine Learning Algorithms
        • Linear Regression
        • Logistic Regression
        • K-Nearest Neighbour
      • Impact of Automation
    • Software Engineering Project
  • AI Tools
  • Software
  • Syllabus
  • Exam
Software Engineering

PROJECT 2 - TEMP CONVERTER

LAB 2 - Number Operations

Lab 2 Overview

Now that we know how to define and input numbers, let's move on to basic number operations and calculations.

TASK 1

  1. Open lab2.py from Project 2 - Temp Converter

Basic Operations

The basic mathematical operations are follows, and all can be found on the numpad of your keyboard:

  • Addition: +

  • Subtraction: -

  • Multiplication: *

  • Division: /

Further Operations

A little more advanced, you may be required to calculate remainders with the modulus operator %.

Or exponents with the exponent operator **.

Here we have used the float() function to convert our string into a a float, and the int() function to convert our second string into an int.

TASK 2

  1. Complete the following requirements:

    • Ask the user for two numbers and store them in variables 'a' and 'b', converting to floats

    • Add 'a' and 'b' and store the result in a variable 'add_result'

    • Subtract 'b' from 'a' and store the result in a variable 'sub_result'

    • Multiply 'a' and 'b' and store the result in 'mul_result'

    • Divide 'a' by 'b' and store the result in 'div_result'

    • Raise 'a' to the power of 'b' and store in 'exp_result'

    • Calculate the modulus of 'a' and 'b' and store in 'mod_result'

    • Print the results of each calculation, with a description of the operation, e.g. "5 plus 3 is 8"

  2. Press Ctrl + F5 to run the program or open a terminal and type python lab2.py

  3. It should run without errors and you should see something like on the right:

Please enter the first number: 7

Please enter the second number: 3

The sum of 7.0 and 3.0 is 10.0

The difference between 7.0 and 3.0 is 4.0

The product of 7.0 and 3.0 is 21.0

The quotient of 7.0 divided by 3.0 is 2.333333

7.0 raised to the power of 3.0 is 343.0

The modulus of 7.0 and 3.0 is 1.0

You should now know how to perform a variety of number operations in Python.
Let's wrap up this lab by pushing our code to GitHub:

TASK 3

  1. Enter a commit message. E.g. "Lab 2 complete"

  2. Press Commit to main

  3. Press Push origin

Report abuse
Page details
Page updated
Report abuse