how do i write a Python program in function.
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)
def calc_fuel(distance, fuel_consumption):
fuel_needed = distance * fuel_consumption / 100.
return fuel_needed
def main():
distance = 500
fuel_rate = 8
fuel = calc_fuel(distance, fuel_rate)
print("Fuel needed is", fuel)
main()
how do i write a Python program in function. calc_fuel which takes two input parameters: distance...
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:...
Python Write a function that takes in two numbers as parameters. The function will then return the value of the first parameters squared by the second parameter. Print the value of the return statement. Take a screenshot of both your code and your properly executed code after you have run it. Submit the screenshots here along with your .txt file.
IN PYTHON Write a program that takes a user-input distance and speed and then calculates an ETA. Your program should work for ANY COMBINATION of distance and speed.
Write a Python program: In main function the user is asked to enter distance traveled and time and then send this information to a Python function that calculates and returns the speed of a car. The function will need to have parameters for distance traveled and time taken for the travel. The speed is calculated as: Speed = distance traveled / time In the main function show how to call this function in a print statement.
PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20
write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...
python program please
Write a function called backwards which takes two parameters. The first is a file object that has already been opened in read mode called essayfile. The second is called filename, which contains the filename for the output file that will need to be properly opened and closed in your function. The function should read from already opened file object line by line. Each line in the file should have the words on the line reversed. For example,...
Write a python function called "get_sma", that takes two input arguments, similar to the example provided. First argument is the original prices of type list, and the 2nd input argument being the number of days we want to calculate SMA, like a 8 day sma or 35 day sma. This function should return a new list of sma price, based on the input day range, and should be able to handle any SMA calculation, like: sma200 for 200 days moving...
Write a function in the C++called summary that takes as its parameters an input and output file. The function should read two integers find the sum of even numbers, the sum of odd numbers, and the cumulative product between two values lower and upper. The function should return the sum of even, odd, ad cumulative product between the lower and upper values. Please write program in C++.
Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...