logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Himani KhatterStatistics
(/5)

749 Answers

Hire Me
expert
Jihye KimHistory
(5/5)

659 Answers

Hire Me
expert
Charlie BilyeuBusiness
(4/5)

603 Answers

Hire Me
expert
Harjeet KunduHistory
(5/5)

818 Answers

Hire Me
Others
(5/5)

document any collaboration relevant to this assignment, in the header comment of the source file, as described in the first assignment.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

 

Reading

Read Chapter 3, review 2.3 (Lists) in Introduction to Computing using Python: An Application Development Focus, Second Edition by Ljubomir Perković.

 

Logistics

Please document any collaboration relevant to this assignment, in the header comment of the source file, as described in the first assignment.

 

Assignment

Implement the functions below in the file csc401_homework2.py which can be found on in the Week 2 folder. You should save the template file I provided and then modify that file by adding the bodies for the functions. When you do, make sure to remove the placeholder pass statements that are currently there.

 

1. Implement the function buy_tickets(age, ticket_type) so that it returns the price of a train ticket purchase, given 2 parameters:

 

1.      age - the age of the purchaser

its data type is a positive integer

 

2.      ticket_type- type of ticket being purchased

its data type is string with 2 legal values: “monthly” and “10-ride”

 

For the sake of this assignment you can assume that the parameters are always valid values.

 

This is the algorithm for calculating a ticket price:

a.  standard 10-ride price is $38

b.  standard monthly price is $159.50

c.  If the purchaser is 65 or older, they get a 10% discount These test cases should all pass:

 

>>> buy_ticket(21, "10-ride") 38

>>> buy_ticket(21, "monthly") 159.5

>>> buy_ticket(70, "monthly") 143.55

>>> price = buy_ticket(70, "10-ride")

>>> price 34.2

 2.      Change the implementation of the function sequences() found in the csc401-homework2.py file so that the following three sequences are printed

      by the for loops found in sequences(). The information below shows how you would call the function and what it would display as a result:

 

 

>>> sequences()

 

9 10 11 12 13 14 15

 

4 8 12 16 20 24 28

 

30 27 24 21 18 15 12

 3.      Implement the function shorten_text(word_list) that takes a list of strings as a parameter and for each word in the list. prints the first character + “…” + the last character of each string, one word per line. If the list provided as a parameter is empty, the function prints a message to that effect. If any of the strings are empty, they are skipped in the display. The information below shows how you would call the function shorten_text() and what it would display for a couple of parameters:

 

>>> shorten_text(['house', 'business', 'trees']) h...e

b...s

t...s

>>> shorten_text([]) Input is empty

>>> shorten_text([‘horse’, ‘’, ‘candy’] h...e

c...y

 4.      Implement a function find_multiples(number_list, target) that takes as parameters a list of numbers and a numeric value. It prints out each value from number_list that is a multiple of the target number. If an empty list is

provided as the first parameter, the function prints an error message. The information below shows how you would call the function and what it would display for some example parameters:

 

>>> find_multiples([1,2,3,4,5,6], 2)

2

4

6

>>> find_multiples([1,2,3,4,5,6], 3)

3

6

>>> find_multiples([], 0) No numbers provided

 

 

 

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme