98-381 Exam QuestionsBrowse all questions from this exam

98-381 Exam - Question 39


The ABC company is creating a program that allows customers to log the number of miles biked. The program will send messages based on how many miles the customer logs.

You create the following Python code. Line numbers are included for reference only.

Exam 98-381 Question 39

You need to define the two required functions.

Which code segments should you use for line 01 and line 04? Each correct answer presents part of the solution? (Choose two.)

Show Answer
Correct Answer: AE

The code provided contains function definitions which need to be well-defined to run the provided calls. For line 01, the function `get_name()` does not take any arguments as it directly prompts the user for their name. Hence, `def get_name():` is correct. For the function `calc_calories`, it needs to take both the miles and a value that indicates how many calories are burned per mile, referred to as 'burn_rate' in the code. Therefore, `def calc_calories(miles, burn_rate):` is appropriate since the provided `burn_rate` matches the second argument 'calories_per_mile' needed for the calculation within the function body.

Discussion

4 comments
Sign in to comment
atxsu
Mar 4, 2020

The answer is A and F, if you choose B or C you get an error: Traceback (most recent call last): File "main.py", line 11, in <module> biker = get_name() TypeError: get_name() missing 1 required positional argument: 'biker' Therefore A and F are the correct option.

s_balla_in
Dec 2, 2019

I think the answer is B and F. def get_name(biker):

mecham
Apr 2, 2020

no. you arent passing the name of biker into the def. you are getting the name From the def.

gargaditya
Oct 14, 2020

Correct,see the function call,there is no argument passed there

gargaditya
Oct 14, 2020

Correct,see the function call,there is no argument passed there

gargaditya
Oct 14, 2020

Be careful between E/F--We need to use the variables defined in 1st line of function definition inside for further computation, what variable name is passed to the function at the time of function call is not important

SherazM
Oct 2, 2021

It is A & F.. I tested out the code.. def get_name(): name = input("What is your name? ") return name def calc_calories(miles,calories_per_mile): calories = miles * calories_per_mile return calories distance = int(input("How many miles did you bike this week? ")) burn_rate = 50 biker = get_name() calories_burned = calc_calories(distance, burn_rate) print(biker, ", you burned about" ,calories_burned, "calories.")