CP1401 – Fundamentals of Problem Solving and Programming

Page 1


CP1401 – Fundamentals of Problem

Solving and Programming

Assignment 1 – SP51 2021

Student Name: John Smith

Student ID: 12345678

Date: 16 May 2025

Overview

This assignment comprises three distinct Python 3 console-based programs, each designed to reinforce foundational programming concepts:Course Hero+3Studocu+3Studocu+3

1. Pay Bill – Demonstrates input, processing, and output operations.

2 Simple Tax – Utilizes decision structures

3 Celsius Calculator – Employs repetition structures Studocu+7Studocu+7Studocu+7Studocu+5Studocu+5Studocu+5Studocu+2St udocu+2Studocu+2

The objective is to enhance proficiency in basic programming constructs without the use of advanced features such as custom functions or data structures not covered in the course

Program 1: Pay Bill

Description

Calculates the total cost for a customer's bill based on the number of items and their individual prices

Pseudocode pgsql

START

Prompt user for the number of items

Initialize total to 0

FOR each item in the number of items

Prompt user for the price of the item

Add the price to total END FOR

Display the total cost END

Sample Code

python

def main():

num items = int(input("Enter the number of items: "))

total = 0 for i in range(num items):

price = float(input(f"Enter the price of item {i+1}: "))

total += price print(f"Total cost: ${total:.2f}")

main()

Program 2: Simple Tax

Description

Determines the tax payable based on the user's annual income using predefined tax brackets Studocu+2Studocu+2Studocu+2

Pseudocode

sql START

Prompt user for annual income

IF income <= 18200

Tax = 0

ELSE IF income <= 37000

Tax = (income - 18200) * 0.19

ELSE IF income <= 87000

Tax = 3572 + (income - 37000) * 0 325 ELSE

Tax = 19822 + (income - 87000) * 0.37

END IF Display the tax payable END

Sample Code

python

def main():

income = float(input("Enter your annual income: ")) if income <= 18200:

tax = 0

elif income <= 37000:

tax = (income - 18200) * 0.19

elif income <= 87000:

tax = 3572 + (income - 37000) * 0.325 else:

tax = 19822 + (income - 87000) * 0.37

print(f"Tax payable: ${tax:.2f}")

main()

Program 3: Celsius Calculator

Description

Converts a range of Celsius temperatures to Fahrenheit, displaying the results in a tabular format

Pseudocode

pgsql

START

Prompt user for the lower limit

Prompt user for the upper limit

Prompt user for the step value FOR temperature from lower to upper limit, incrementing by step

Calculate Fahrenheit = (Celsius * 9/5) + 32

Display Celsius and Fahrenheit END FOR END

Sample Code python

def main():

lower = int(input("Enter the lower limit of Celsius: "))

upper = int(input("Enter the upper limit of Celsius: ")) step = int(input("Enter the step value: ")) print("Celsius\tFahrenheit") for celsius in range(lower, upper + 1, step): fahrenheit = (celsius * 9/5) + 32 print(f"{celsius}\t{fahrenheit:.2f}")

main()

Reflection

Completing this assignment reinforced my understanding of fundamental programming concepts such as loops, conditionals, and user input handling. While the tasks were straightforward, ensuring accuracy in calculations and user prompts required careful attention For students seeking additional support, exploring resources that offer Programming assignment help can provide valuable insights and guidance.

References

● James Cook University CP1401 Lecture Materials

● Python Official Documentation: https://docs.python.org/3/GitHub+13Course Hero+13Studocu+13

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.