Question

Part 1 Below you are given the algorithms for two functions, main and doMath. Implement both...

Part 1

Below you are given the algorithms for two functions, main and doMath. Implement both in Python.

function main():

get x from user

get y from user

call doMath(x,y)

function doMath(lhs, rhs):

sum = lhs + rhs

diff = lhs – rhs

product = lhs x rhs

quotient = lhs / rhs

display sum, diff, product, and quotient on separate lines

Part 2

Add a new function called get_fuel to your Python program.

calc_fuel which takes two input parameters:

distance fuel_consumption.

The function should calculate :

fuel_needed = distance * fuel_consumption / 100.

The function should then return fuel_needed.

Now add the following lines at the end of main():

distance = 500

fuel_rate = 8

fuel = get_fuel(distance, fuel_rate)

print(“Fuel needed is“, fuel)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def main():
    x = float(input("Enter x: "))
    y = float(input("Enter y: "))
    doMath(x, y)


def doMath(lhs, rhs):
    sum = lhs + rhs
    diff = lhs - rhs
    product = lhs * rhs
    quotient = lhs / rhs
    print("sum =", sum)
    print("difference =", diff)
    print("product =", product)
    print("quotient =", quotient)


main()

def get_fuel(distance, fuel_consumption):
    fuel_needed = distance * fuel_consumption / 100.
    return fuel_needed


def main():
    distance = 500
    fuel_rate = 8
    fuel = get_fuel(distance, fuel_rate)

    print("Fuel needed is", fuel)


main()



Add a comment
Know the answer?
Add Answer to:
Part 1 Below you are given the algorithms for two functions, main and doMath. Implement both...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement a Python function that prints integers from a to b. The main part of the...

    Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function. # Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input("Please prvide a value for a: ")) b = int(input("Please prvide a value for b: ")) display(a,b)

  • Part 2: Preperation for ML algorithms %run part2-setup.py 7. Write the function prepare_data(data...

    Part 2: Preperation for ML algorithms %run part2-setup.py 7. Write the function prepare_data(dataset_dict), which takes a dataset dictionary and returns a tuple (X,y) that holds the datamatrix and the labels In [3] : .Both X and y are of type numpy arrays . If the output variable is numeric (np.issubdtype(y.dtype, np.number)) it should be kept as is, otherwise it should be discretized using the command pandas.factorize) (use default function parameters). .Categorical features (whose columns are specified in the configuration file)...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • Write a program which uses four functions [ 1 for each part of the assignment ]:...

    Write a program which uses four functions [ 1 for each part of the assignment ]: 1. Display all numbers between 1 and n, where n is an input from the user. 2. Display the reverse of a number n, where n is input from the user. 3. Display the following pattern for n rows, where n is input from the user: (ON PYTHON IDLE 3.7.2) Again, define a function for each part of the assignment, define a mainO function...

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • python code DC Final Project Implement a class Car with the following properties. A car has...

    python code DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...

  • I am supposed to a pseudocode function named max that accepts two integer values as arguments...

    I am supposed to a pseudocode function named max that accepts two integer values as arguments and returns the value that is greater of the two. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is greater of the two. Is everything correct and complete? //Pseudocode //This function takes two integers as parameters: x and y Begin : Max(x,y) If(x>y) then MAX=x Else MAX=y End if Return...

  • You should implement several functions that the Phone Contacts program will need Each function with take...

    You should implement several functions that the Phone Contacts program will need Each function with take in data through the parameters (i.e., variables names listed in parentheses) and make updates to data structure that holds the contact information, return, or print information for a particular contact. The parameters needed are listed in the table below and each function is described below that 1. Make an empty dictionary and call it 'contacts'. Where in your code would you implement this? Think...

  • In this project, you will use functions and dictionaries to track basketball players and their respective...

    In this project, you will use functions and dictionaries to track basketball players and their respective points, then display statistics of points made. You will need three functions as follows: def freeThrowMade(playerDictionary, playerName) - this function will add 1 point to the player's total score def twoPointMade(playerDictionary, playerName) - this function will add 2 points to the player's total score def threePointMade(playerDictionary, playerName) - this function will add 3 points to the player's total score Each of these functions has...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT