Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine

Write 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 object.  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 object.

Step by Step Solution

3.32 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

Heres a Python function partyVolume that reads a file as described processes the input and returns t... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

Demonstrate knowledge of the company/organization and the position.

Answered: 1 week ago