Starting from:

$34.99

CSC401 Assignment 1 Solution


Reading
Read Chapter 1, 2* and 3 in Introduction to Computing using Python: An Application Development Focus, Second Edition by Ljubomir Perković.
*Skip tuples in chapter 2.3.
Logistics
You need to do this assignment on a computer which has Python 3 installed on it. Python 3.8.5 download page can be found here.
A submission that includes code which does not run will not get any points for the part unless specifically documented reason of the error.
Assignment
1. Interactive input (20pt)
a. (10pt) Write a program that asks for user's first and last name in two separate requests. And then print out user's first name and last name in one line as shown below.



b. (10pt) Write a program that asks for a decimal value as account balance and another decimal value as annual interest rate. Calculate the account balance next year assuming there is no deposits or withdrawals and print out the result in the following manner. Do not concern yourself with formatting decimal places for this question. We will cover formatting in chapter 4.

Hint: new balance is the previous balance plus the interest payment. Interest payment is the previous balance multiplied by interest rate. Be careful about the percentage.


2. Lists and Decision (20pt)
You keep a list of your favorite colors (pick around 5 or 6). Write a program that allows the user to enter their favorite color. If that color is also one of your favorites, reply by saying so, otherwise say that you don't like the color.
Hint: Do use a list for your colors.

3. Decisions (20pt)
If there is a vote at a meeting, the outcome is based on the number of yes and no votes (abstains are not counted). If more than 1/2 of the votes are yes, then the proposal passes, and otherwise it fails. Write a program that asks the user for the number of yes and no votes (two separate prompts), and then prints the outcome of the vote ('pass',
'fail').
Hint: In a first step compute the total number of votes. Then if, else.
4. Decisions and loops (40pt)
a. (20pt) Write a function called isNumberPresent() that accepts a list of numbers and a number to search for. If the number is present in the list, the function should return the boolean value (not the string!) True. Otherwise, the function should return the boolean value (not the string!) False.

b. (20pt) Write a program that lists all the composers on a list, say ['Antheil', 'Saint-Saens', 'Price', 'Easdale', 'Nielsen'], whose last letter is the same as the first letter. (so Saint-Saens, Easdale and Nielsen should get listed, but not the others.)

Hint: How can string comparison be case insensitive?

Submission
Submit the assignment using Assignment 1 folder. Submit only a single python file using your name as file name (e.g. Jay_Tang_Assign_1.py).

More products