Question

In: Computer Science

Create a Python file named num_sum.py that contains: The definition of two functions: volume - accepts...

Create a Python file named num_sum.py that contains:

  • The definition of two functions:
    • volume - accepts three parameters and returns the product of them, but displays nothing
    • sum_of_nums - accepts 1 or more numbers and returns their sum, but displays nothing
  • A print function call that includes a call to volume, passing 2, 3, and 4
  • A print function call that includes a call to sum_of_nums, passing 1, 2, 3, 4, and 5

Solutions

Expert Solution

# TEXT CODE

# Defining function volume

def volume(arg1, arg2, arg3):
  
# return the product of three arguments
return arg1*arg2*arg3


# Defining function sum
# The symbol * is used to take variable number of arguments, by convention, * is used with word args

def sum(*args):
  
# if zero arguments are passed simply return
if len(args) == 0:
return
  
#initialize varible res to 0, res stores sum of parameters
res = 0
  
# iterate through args
for arg in args:
  
# add arg to res, and update res
res = res + arg
  
  
# finally, return the res
return res

# driver code to check the above to functio with print function

# first call to print function with volume
print("Volume is:", volume(2, 3, 4))

# second call to print function with sum
print("Sum is:", sum(1, 2, 3, 4, 5))

#SCREENSHOTS

# CODE

# OUTPUT


Related Solutions

IN PYTHON PLEASE Create a file lists.py that contains the following functions: sumOfOdd(intList) The parameter intList...
IN PYTHON PLEASE Create a file lists.py that contains the following functions: sumOfOdd(intList) The parameter intList is supposed to be a list of integers. The function returns the sum (addition) of the odd integers from intList, and leaves intList not modified For instance, given [1,2,3,4], the function returns 4. The function performs no I/O. productOfEven(intList) The parameter intList is supposed to be a list of integers. The function returns the product (multiplication) of the even integers from intList, and leaves...
Using Python. A file exists on the disk named students.txt. The file contains several records, and...
Using Python. A file exists on the disk named students.txt. The file contains several records, and each record contains two fields: (1) the student’s name, and (2) the student’s score for the final exam. Write code that deletes the record containing “John Perz”as the student name. This the code i have so far but it's not working: import os def main(): found=False search='John Perz' student_file = open('student.txt','r') temp_file = open('temp_students.txt','w') name=student_file.readline() score='' while name !='': score=student_file.readline() name=name.rstrip('/n') score=score.rstrip('/n') if name...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on the command line 2. For each file name provided, delete any line that contains the string: qwe.rty When the changes are completed, the script should display the total number of files scanned, and the total number of files changed. Example Command: assessment-script-a file.a file.b file.c file.d file.e    Example Output: 5 files scanned, 3 files changed 3. Your script should include a series of...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching pairs of vehicle models and their respective makes Separate out the individual make and model on each line of the file Add the vehicle make to one list, and the vehicle model to another list; such that they are in the same relative position in each list Prompt the user to enter a vehicle model Search the list containing the vehicle models for a...
Create a Python file num_utils.py that includes: A function sum_of_nums that accepts 1 or more number...
Create a Python file num_utils.py that includes: A function sum_of_nums that accepts 1 or more number parameters and returns their sum without displaying anything A function product_of_nums that accepts 1 or more number  parameters and returns their product without displaying anything A function average_of_nums  that accepts 1 or more number  parameters and returns their average without displaying anything Create a Python file test_num_utils.py that: Imports num_utils Defines a function test_num_utils that demonstrates the use of the utilities in num_utils.py Executes test_num_utils
USING JAVASCRIPT Create a file name dayOfWeek.js and write an arrow function named dayOfWeek that accepts...
USING JAVASCRIPT Create a file name dayOfWeek.js and write an arrow function named dayOfWeek that accepts a Date object dateStr and returns a string that is the day of the week in English form (i.e. “Sunday”, “Monday”, etc.). Test your function by creating a date object that is a significant date to you (such as your birthday) and passing that date object to your function. Test your function at least twice with two different dates. Submit the dayOfWeek.js file to...
Consider a text file that you will create named “employees.txt”. The file contains data organized according...
Consider a text file that you will create named “employees.txt”. The file contains data organized according to the following format:John Smith 10 15Sarah Johnson 40 12Mary Taylor 27 13Jim Stewart 25 8For instance, “John” is the first name, “Smith” is the last name, “10” is the number of hours per week, and “15” is the hourly rate.Write a program that computes the weekly salary of each employee. The program prints the first name, last name, and weekly salary of each...
​​​​Python Create a new file named compute_cost.py. Write your name and date in a comment. Create...
​​​​Python Create a new file named compute_cost.py. Write your name and date in a comment. Create a variable named base_fee and set the value to 5.5. Prompt the user for the zone. The zones can be an integer value from 1 to any value for the zone. Convert the zone to an integer. Display the zone on the SenseHat with a scroll speed of 0.3, make the text blue, and the background yellow. Scroll "The zone is " and the...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT