Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Foundations of Programming Python Exam - Topic 4 Question 10 Discussion

SIMULATIONComplete the function get_max(a, b) that returns the larger of two numbers. If they are equal, return either one.def get_max(a, b):# TODO: Return the larger of a and bpass
A) See the Step by Step Solution below in Explanation

WGU Foundations of Programming Python Exam - Topic 4 Question 10 Discussion

Actual exam question for WGU's Foundations of Programming Python exam
Question #: 10
Topic #: 4
[All Foundations of Programming Python Questions]

SIMULATION

Complete the function get_max(a, b) that returns the larger of two numbers. If they are equal, return either one.

def get_max(a, b):

# TODO: Return the larger of a and b

pass

Show Suggested Answer Hide Answer
Suggested Answer: A

==========

Step 1: The function receives two parameters: a and b.

Step 2: Compare the two values using an if statement.

Step 3: If a is greater than or equal to b, return a.

Step 4: Otherwise, return b.

Correct code:

def get_max(a, b):

if a >= b:

return a

else:

return b

Simplified correct code:

def get_max(a, b):

return max(a, b)

Example:

print(get_max(10, 20))

print(get_max(30, 15))

print(get_max(5, 5))

Output:

20

30

5


Contribute your Thoughts:

0/2000 characters
I believe we just need a simple if statement to compare a and b, but I hope I remember the syntax correctly!
upvoted 0 times
...
Ivette
5 days ago
I practiced something like this before, but I can't recall if I need to handle types explicitly.
upvoted 0 times
...
Layla
10 days ago
This seems straightforward, but what if both numbers are negative? Does it change how we compare them?
upvoted 0 times
...
Emiko
15 days ago
I think I remember using the max() function in a similar practice question, but I'm not sure if that's allowed here.
upvoted 0 times
...

Save Cancel