0% found this document useful (0 votes)
8 views5 pages

Cosi10 Pa5

The document outlines Programming Assignment 5 for COSI 10A, focusing on problem-solving in Python through five distinct programming tasks. Each task requires the implementation of specific functions and handling user input, file operations, and data processing. Submission guidelines emphasize proper file naming, code structure, and adherence to stylistic guidelines.

Uploaded by

kpk6jbwt7p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Cosi10 Pa5

The document outlines Programming Assignment 5 for COSI 10A, focusing on problem-solving in Python through five distinct programming tasks. Each task requires the implementation of specific functions and handling user input, file operations, and data processing. Submission guidelines emphasize proper file naming, code structure, and adherence to stylistic guidelines.

Uploaded by

kpk6jbwt7p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

COSI 10A (FALL 2024)

Introduction to Problem Solving in Python

Programming Assignment 5

Program Description:

This assignment will test your understanding of the definite loops. Write three scripts to solve the problems
below. All your programs should follow the submission guideline at the end.

Problem 1:

Write a program that gets input from the user and writes it to the file. Your program needs to have at least
two functions, main and fileHandler. The function fileHandler accepts the output file name as a
parameter, asks the user to type the texts line by line to write, and stores the input to given file until user
types Done.

The output of your program needs to be exactly like the followings:


Type the name of an output file: out.txt

Type a line to file or type ‘Done’ to finish

: File processing in programming

: is a very useful tool.

: Done

Writing to file out.txt is completed.

____________________________________________________________________

In out.txt,

File processing in programming

is a very useful tool.

Problem 2:

Write a program that counts the number of appearances for the given character. Your program needs to have
at least two functions, main and charCount. The main gets a filename and a target character and checks
the give file exists or not. If the file does not exist, your program asks the user to type a valid file name.
Similarly, if the user submitted the string with more than 2 characters, your program asks the user to submit
the valid character. The charCount gets the string data from the file and the target word, counts the
number of appearances of the target word in the string data using dictionary, and returns the number of
appearances. Note that charCount is case-insensitive, if the target character is ‘t’, then, your program
needs to find both ‘t’ and ‘T’. You may use the file PA5_1.txt which is available in the course Moodle
page.

The output of your program needs to be exactly like the followings:


Enter the filename: PA.tt

There's no such file.

Enter the filename: PA5_1.txt

Enter the character to count: at

You need to submit a single character.

Enter the character to count: t

The character 't' appears 81 times in the file.

Problem 3:

Write a program that finds the names of the movie with highest and lowest rating in the file. You need to
use PA5_2.csv for this problem. Each line of the file has three values: name, rating, and number of votes,
and these three are separated by ‘,’. Your program needs to have at least three functions, main,
findMin and findMax. Both findMin and findMax get a list of data and returns the index of the
minimum or maximum value. Your program needs to print the title of a movie with highest and lowest
number of votes and highest and lowest ratings.

Note that you can separate the line by comma using split(’,’).

The output of your program needs to be exactly like the followings:


The movie with highest votes: Eternal Vanguard (13178)

The movie with lowest votes: Dreamweaver’s Descent (19)

The movie with highest ratings: Eternal Vanguard (7.4)

The movie with lowest ratings: Dreamweaver’s Descent (3.0)

Problem 4:

Write a program that checks the given dictionary has unique values. Your program needs to have at least
two functions, main and isUnique. The functions isUnique accepts a dictionary whose keys and
values are strings as a parameter and returns True if no two keys map to the same value (and False if
any two or more kyes do map to the same value). You may assume that the dictionary is given in the main
(no need to use input function).

The output of your program needs to be exactly like the followings:


Marty / Stepp

Stuart / Reges

Jessica / Wolk

Allison / Abourn

Hal / Perkins

All values are unique.

____________________________________________________________________

Marty / Perkins

Stuart / Reges

Jessica / Wolk

Allison / Abourn

Hal / Perkins

There are duplicate values.

Problem 5:

Write a program that manages the inventory to track products and their quantities in stock. Your program
needs to have at least three functions, main, addProduct, and removeProduct. The main gets the
name of the product and quantity that user wants. If the user gives a positive integer, it means that product
is added to the inventory. But, for negative number, the product is retrieved from the inventory. The
addProduct gets the inventory dictionary, product name, and quantity of the product as parameters and
updates the inventory using the product name and quantity. The removeProduct gets the inventory
dictionary, product name, and quantity and updates the inventory using the product name and quantity.
When the quantity is less than the user wants, your program needs to notify the user. If the quantity reaches
0, then your program needs to delete the product from the inventory. Your programs repeat this until the
user types Done.

The output of your program needs to be exactly like the followings:


Banana 30

Apple 15
Banana -50

Not enough stock. You have 30 Banana.

Orange -10

The product Orange does not exist.

Banana -30

Banana -1

The product Banana does not exist.

Done

Submission guidelines and Grading:

Submit via Moodle a zip file named yourfirstname_yourlastname_PA5.zip which contains all
your python scripts. Please make sure to use the exact same file names and function names, including
identical capitalization.

Your program should be submitted via Moodle the day it is due (for late policy check the syllabus).

Write each program in a separate file named Problem1.py, Problem2.py, etc. You should not have any
code, except a call to your main function, outside of a function. You should use the main function to call
other functions that implement the solution.

You also need to include comments in your code. Include a header comment at the beginning of each
file with some basic information and a description of the program in your own words.
# Name
# COSI 10a, Fall 2024
# Programming Assignment 5
#
# Description: ...

For this assignment, you should limit yourself to the Python features covered up to lecture 22. Though
we will cover more material while you work on this assignment, please do not use it on this assignment.

You will be graded on:

External Correctness: The output of your program should match exactly what is expected.
Programs that have errors will not receive points for external correctness.

Internal Correctness: Your source code should follow the stylistic guidelines shown in class.
Remember to include the comment header at the beginning of your program and comment your
code.

You might also like