Use Python for this question:  Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine the a Volume object that is the result of many people at a party turning the Volume up and down. More specifically: the first line of the file is a number that indicates the initial value of a Volume  The remaining lines consist of a single character followed by a space followed by a number.  The character will be one of ‘U” or ‘D’ which stand for “up” and “down” respectively.  The function will create a new Volume object and then process each line of the file by calling the appropriate method of the Volume object which changes the value of the Volume.  The function then returns the final Volume object.   Guidelines/hints:

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Use Python for this question: 

  1. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine the a Volume object that is the result of many people at a party turning the Volume up and down. More specifically: the first line of the file is a number that indicates the initial value of a Volume  The remaining lines consist of a single character followed by a space followed by a number.  The character will be one of ‘U” or ‘D’ which stand for “up” and “down” respectively.  The function will create a new Volume object and then process each line of the file by calling the appropriate method of the Volume object which changes the value of the Volume.  The function then returns the final Volume object.   Guidelines/hints:

    • This is a standalone function, it should NOT be inside (indented within) the class. It should be listed in the module after the Volume class and without indentation.

    • Note that the first line of the file will be treated differently than all the other lines. Probably the easiest way to do this is to 1) open the file, 2) call the .readline() method (no s!) which reads a single line, the initial value of the Volume, then 3) call the .readlines() method which reads the rest of the lines.  Item 2) will be used to set the initial Volume and 3) will be iterated over to represent turning the volume up and down some number of time.
    • Make sure you return the final Volume

Please run a doctest to make sure the function for this question, returns/prints the correct output.

Output for this question is in the attached image

##### partyvolume #####
>>> partyVolume ('partyl.txt')
Volume (6.35)
>>> partyvolume ('party2.txt')
Volume (3.75)
>>> partyVolume ('party3.txt')
Volume (0.75)
# make sure return not print
>>> partyVolume ('partyl.txt')==Volume (6.35) # return not print
True
>>> partyVolume ('party2.txt')==Volume (3.75)
True
>>> partyVolume ('party3.txt')==Volume (0.75)
True
Transcribed Image Text:##### partyvolume ##### >>> partyVolume ('partyl.txt') Volume (6.35) >>> partyvolume ('party2.txt') Volume (3.75) >>> partyVolume ('party3.txt') Volume (0.75) # make sure return not print >>> partyVolume ('partyl.txt')==Volume (6.35) # return not print True >>> partyVolume ('party2.txt')==Volume (3.75) True >>> partyVolume ('party3.txt')==Volume (0.75) True
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning