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 1 - Numbers

Lab 1 Overview

So far we have learned how to work with text data. Let's move on to how numbers work in Python.

TASK 1

  1. Ensure that you are signed into your GitHub account

  2. Accept the assignment: Project 2 - Temp Converter

  3. Clone the repository to your computer using GitHub Desktop, or open it online using Codespaces

  4. Open lab1.py

Data Types

When you declared a variable in the past project you did so like this: name = "David"

The double quotation marks around the name mean that it is a string, text data. We can include a number in there though, so what's the problem?

As you can see, if we try to perform any sort of mathematical operation on these numbers, they are not treated numerically. It is just joining strings.
With numbers, we need to ditch the quotation marks. This tells Python that we want a different type of data.

Much better, we get the correct answer: 10
What is happening under the hood? Let's investigate data types using the type() function:

When you run the example above, you can see that num1 is a str (string, text data) and that num2 is an int (integer, whole number).

In addition to int for for whole numbers, we can use float for decimal numbers.

Getting Numerical Input

This poses a problem, run the example below and enter a number:

When we get input from the user, it is always a str.
We need to use a function to convert the input into the type of number we need.

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:

    • Define a variable 'a' and assign it an integer value

    • Define a variable 'b' and assign it a decimal value

    • Print the values and types of 'a' and 'b'

    • Ask the user for a whole number and store it in a variable 'x', converting to an integer

    • Ask the user for a decimal number and store it in a variable 'y', converting to a float

    • Print the values and types of 'x' and 'y'

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

  3. The program should run without any errors and you should see that your variables are either <class 'float'> or <class 'int'>

You should now know the difference between strings, integers and floats in Python and be able to work with all three.
Let's wrap up this lab by pushing our code to GitHub:

TASK 3

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

  2. Press Commit to main

  3. Press Push origin

Video

Here is a video from Harvard's CS50P course that covers the content of the next 3 labs. Optional, but useful if you need further explanation.

CS50P - Temp Converter - Lab 1 - 1696476475751.mp4
Report abuse
Page details
Page updated
Report abuse