Concept explainers
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / VARIABLE-NAME) * VARIABLE-NAME
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, VARIABLE-NAME, VARIABLE-NAME)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, VARIABLE-NAME, VARIABLE-NAME)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, VARIABLE-NAME, VARIABLE-NAME)))
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
1) Below is your updated program where VARIABLE-NAME is updated with actual variable
2) Program does below activities
- It reads the user input for miles per gallon and dollers per gallon
- Call the function driving_cost for driven miles 10. 50. 400
- The function driving_cost
- takes input parameters like driven_miles, miles_per_gallon, dollars_per_gallon
- Calculate trhe cost of travel using formula
- return the calculated value
- Main program prints the return value from driving_cost function for 10.50 and 400 miles
3) Save program in pythoin file and run
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / miles_per_gallon) * dollars_per_gallon
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, miles_per_gallon, dollars_per_gallon)))
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / miles_per_gallon) * dollars_per_gallon
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, miles_per_gallon, dollars_per_gallon)))
From Student
When i put in the code this was the output which is wrong.
Traceback (most recent call last): File "main.py", line 9, in <module> miles_per_gallon=float(input()) #leave this statement as is. EOFError: EOF when reading a line
1) Below is your updated program where VARIABLE-NAME is updated with actual variable
2) Program does below activities
- It reads the user input for miles per gallon and dollers per gallon
- Call the function driving_cost for driven miles 10. 50. 400
- The function driving_cost
- takes input parameters like driven_miles, miles_per_gallon, dollars_per_gallon
- Calculate trhe cost of travel using formula
- return the calculated value
- Main program prints the return value from driving_cost function for 10.50 and 400 miles
3) Save program in pythoin file and run
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / miles_per_gallon) * dollars_per_gallon
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, miles_per_gallon, dollars_per_gallon)))
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / miles_per_gallon) * dollars_per_gallon
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, miles_per_gallon, dollars_per_gallon)))
From Student
When i put in the code this was the output which is wrong.
Traceback (most recent call last): File "main.py", line 9, in <module> miles_per_gallon=float(input()) #leave this statement as is. EOFError: EOF when reading a line
- Function Name: compliments Parameters: answer1 - a boolean (True or False) representing whether the user is "smart" answer2 - a boolean (True or False) representing whether the user is "awesome" answer3 - a boolean (True or False) representing whether the user is "fun" Description: Write a function that outputs a string of compliments based on the adjectives selected by the inputs. Use the inputs True and False. The function should return the string “You are” concatenated with the compliments that are true. The three compliments should be: "smart" "awesome" and "fun". If none of the compliments are true, print the string “Goodbye.” instead. Test Cases: >>>compliments(True, True, True) You are smart awesome fun. >>>compliments(False, True, False) You are awesome. >>>compliments(False, False, False) Goodbye.arrow_forwardIn the code below, set the allocated amount variable to the exact amount of space that should be allocated and pointed to by float *rainfall. 1 #include #include 4 int main() { int allocated_amount; 7 // Set the value of allocated amount: 8 f 9. 10 return 0; 11 } LOarrow_forwardGiven two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar variable that performs the following operations: • Drives input number of miles forward • Drives input number of miles in reverse Honks the horn • Reports car status SimpleCar.h contains the struct definition and related function declarations. SimpleCar.c contains related function definitions. Ex: If the input is: 100 4 the output is: beep beep Car has driven: 96 miles 1 #include 2 3 #include "SimpleCar.h" 5 int main() { 6 8 9 10 } /* Type your code here. */ return 0; Current file: main.c Load default templatearrow_forward
- B- Declare a constant of character type with initial value='G' o Const char LETTER ='G'; O #define LETTER 'G'arrow_forward// EmployeeBonus.cpp - This program calculates an employee's yearly bonus. #include <iostream> #include <string> using namespace std; int main() { // Declare and initialize variables here string employeeFirstName; string employeeLastName; double numTransactions; double numShifts; double dollarValue; double score; double bonus; const double BONUS_1 = 50.00; const double BONUS_2 = 75.00; const double BONUS_3 = 100.00; const double BONUS_4 = 200.00; // This is the work done in the housekeeping() function cout << "Enter employee's first name: "; cin >> employeeFirstName; cout << "Enter employee's last name: "; cin >> employeeLastName; cout << "Enter number of shifts: "; cin >> numShifts; cout << "Enter number of transactions: "; cin >> numTransactions; cout << "Enter dollar value of transactions: "; cin >> dollarValue; // This is…arrow_forwardc++arrow_forward
- #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { constdouble MONSTERA_PRICE =11.50; constdouble PHILODENDRON_PRICE =13.75; constdouble HOYA_PRICE =10.99; constint MAX_POTS =20; constdouble POINTS_PER_DOLLAR =1.0/0.75; char plantType; int quantity; double totalAmount =0.0; int totalPoints =0; int availablePots =0; double plantPrice =0.0; cout << "Welcome to Tom's Plant Shop!" << endl; cout << "******************************" << endl; cout << "Enter your full name: "; string fullName; getline(cin, fullName); output: compiling code... Welcome to Tom's Plant Shop!----------------------------------------Enter your full name: ______ Available plants:M - Monstera ($ 11.5)P - Philodendron ($13.75)H - Hoya ($10.99)Q - Quit shoppingEnter the plant type (M/P/H/Q): ________ Part 1 Tom has recently started a plant-selling business, and he offers three different types of plants, namely Monstera,…arrow_forwardC++arrow_forward#include <iostream>using namespace std; double average(int sum_of_grades,int num_grades){return sum_of_grades/(float)num_grades;} int main() {int num_grades,grade,sum=0;char grade_value;cout<<"Enter the number of grades"<<endl;cin>>num_grades;for(int i=0;i<num_grades;i++){cout<<"Enter a numeric grade between 0-100"<<endl;cin>>grade;sum+=grade;}double avg=average(sum,num_grades);if(avg>=90 && avg<=100)grade_value='A';else if(avg>=80 && avg<=89)grade_value='B';else if(avg>=70 && avg<=79)grade_value='C';else if(avg>=60 && avg<=69)grade_value='D';else if(avg>=0 && avg<=59)grade_value='F';cout<<"The grade is "<<grade_value;} review if the written c++ code is correct then organize the code and write comments for each part of the program explaining what they do.arrow_forward
- C++ enum Major {COMPUTER_SCIENCE, COMPUTER_SECURITY_INFO_ASSURANCE, CYBER_SECURITY, ELECTRICAL_ENGINEERING, OTHER}; struct Name { string first; string last; char middleInitial; }; struct StudentRecord { Name studentName; Major major; string email; }; StudentRecord student12; Suppose you are student12. Show the C++ statements used to fill in all of your information for your StudentRecord. Show how would you assign the third letter from the email field to a local char variable called myChar.arrow_forwardFill-in-the-Blank If function showValue has the following header: void showValue(int quantity) you would use the statement _________ to call it with the argument 5.arrow_forwardc++ help Write a function that will ask the user to input number of hours worked and pay rate and return both values to the calling function Write the statement to call this function = Write the prototype for this function = Write a function that will receive the hours worked and the pay rate and calculate and return the gross pay Write the statement to call this function = Write the prototype for this function = Write a function that will receive the hours worked , the pay rate, the gross pay and display these values with proper headings Write the statement to call this function = Write the prototype for this function = Write a function that receives 3 values, calculate and return the average of them Write the statement to call this function = Write the prototype for this function =arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education