CSE101 Assignment #2 Solved

34.99 $

Description

5/5 - (1 vote)

Instructions

For each of the following problems, create an error-free Python program.
– Each program should be submitted in a separate Python file that follows a particular naming convention: Submit the answer for problem 1 as “Assign2Answer1.py” and for problem 2 as “Assign2Answer2.py” and so on.
– These programs should execute properly in VS Code using the setup we created in lab.
– At the top of every file add your name and Stony Brook email address in a
comment.
– Include all the provided test cases in your solutions – for test cases that just return a value, make sure to add a print() statement so you can see the result.

Regarding working in pairs:
– You are welcome to work with a partner on the homework assignment, but you MUST write both your names and email addresses in each file in a comment. Only one person needs to submit the homework on Blackboard.
– You are only allowed to work together with one other person – larger group submissions or collaborations (beyond high-level discussions of problems, as stated on the syllabus) are not allowed.

Problem 1: (2 points)

Download the provided Assign2Answer1.py file and bring it into VS Code.
The provided program has a function named shapeName that is supposed to print out the name of a shape that has 3 to 6 sides. However, the provided program does not work because it has 3 different bugs. Find and fix these three bugs.

Additionally, in the code, write a comment (starting with # ) describing each bug and what you needed to do to fix it.

Problem 2 (1 points)

Write a Python function named isEven that takes a number as a parameter and if the number is even it prints “Is even” and if the number is odd it prints “Is odd”. Call your function and test it with at least 3 different numbers.

Note: below is what a sample function calls to your program should look like and the resulting output. The Python code is on lines that start with >>> and the printed output is below it.

>>>isEven(4) Is even
>>>isEven(7)
Is odd

Problem 3 (2 points)

Complete the function waterBill, which computes and returns the monthly water bill for a particular house. The local water authority charges a flat monthly fee of $50 per house plus $0.75 per gallon for each gallon consumed above 110 gallons. The function takes one argument, which is the number of gallons of water consumed during a particular month.
Function Call Return Value
waterBill(60) 50 or 50.0
waterBill(110) 50 or 50.0
waterBill(115) 53.75
waterBill(145) 76.25

Problem 4 (2 points)

You will write a program that calculates a discount for a movie ticket price based on the customer’s age. Complete the function movieTicket, which returns the cost to see a movie, based on the normal ticket price and the ticket holder’s age. The discounting works as follow:
• infants less than 2 years of age: free! (return 0)
• children from 2 to 11 years of age, inclusive: apply a 15% discount • adults 65 years of age and up: apply a 20% discount • everyone else pays the normal price.
The function takes two arguments: the age of the customer and the normal ticket price, in that order.
Function Call Return Value
movieTicket(60, 12) 12 or 12.0
movieTicket(1, 17) 0 or 0.0
movieTicket(72, 15.5) 12.4
movieTicket(8, 11) 9.35

  • assign_2-070sh3.zip