0

I am stuck on this homework problem. This is the assignment question and prompt:


"Define stubs for the functions get_user_num() and compute_avg(). Each stub should print "FIXME: Finish function_name()" followed by a newline, and should return -1. Each stub must also contain the function's parameters.

Sample output with two calls to get_user_num() and one call to compute_avg():

FIXME: Finish get_user_num()
FIXME: Finish get_user_num()
FIXME: Finish compute_avg()
Avg: -1"

I have tried a bunch of different things, but I just keep getting errors. I'm completely lost on this one. This is what I have so far:


def get_user_num(user_num1, user_num2):
    get_user_num = -1
    avg = user_num1 + user_num2
    return get_user_num

user_num1 = 0
user_num2 = 0
avg_result = 0

user_num1 = get_user_num()
user_num2 = get_user_num()
avg_result = compute_avg(user_num1, user_num2)

print('Avg:', avg_result)

And I am just getting error message after error message. I know I have to use def to define something, but I'm lost.

5
  • 4
    The task says to write stubs - functions that simply print "FIXME: Finish <function_name>". You don't need to calculate anything in your functions, just make them print what the task says, return -1, and that's it Commented Sep 29, 2021 at 22:36
  • Hey thank you for responding, okay I tried this: print('FIXME: Finish function_name()') user_num1 = 0 user_num2 = 0 avg_result = 0 user_num1 = get_user_num() user_num2 = get_user_num() avg_result = compute_avg(user_num1, user_num2) print('Avg:', avg_result) But now it says :Exited with return code 1. Traceback (most recent call last): File "main.py", line 7, in <module> user_num1 = get_user_num() NameError: name 'get_user_num' is not defined" Commented Sep 29, 2021 at 22:40
  • 2
    @Aeroangel please edit your post with the code in your comment. That's pretty unreadable given that it isn't indented and there are no line breaks. Commented Sep 29, 2021 at 22:44
  • 2
    Well, does this code define a function named get_user_num? It doesn't (there's no def get_user_num statement). Yet it calls this (non-existent!) function in user_num1 = get_user_num(). What does it mean to call a function that doesn't exist? Nothing, so you get the error Commented Sep 29, 2021 at 22:44
  • Honestly, this is one of the best homework questions I've seen! Except for minor formatting it actually shows some effort in a clean way. +1 Commented Sep 29, 2021 at 23:18

2 Answers 2

2

So let's start simple, you got some statement, let's parse it into simple parts and connect it into the Python world.

  • Define stubs

    noun Something cut short or arrested in development. (source)

  • for the functions get_user_num() and compute_avg()

    The keyword def introduces a function definition. It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line, and must be indented. (source)

  • Each stub should print

    Check how to output something with Python to the console.

  • followed by a newline

    As in do not make two FIXME lines collapse onto each other like this: FIXME: somethingFIXME: something else.

    the Unix end-of-line convention '\n', the Windows convention '\r\n', and the old Macintosh convention '\r'... (source)

  • and should return -1

  • Each stub must also contain the function's parameters.

    Undefined anywhere. So either use something you'd normally use for a let's say maths function or likes

  • Sample output with two calls to get_user_num() and one call to compute_avg(): ...

    This is how the final program should behave once executed. A function is called by first being ensuring it's been defined previously, then writing its name + () e.g. func().

    Judging by the undefined func arguments and two related functions, you might want to connect the two functions either directly or with an intermediary item holding the result.

After these steps you should be able to create the final program. Do not try to create it at once, utilize the bullet points as small steps and always check if the file still works (executes properly). Create multiple files (copy-paste) when necessary.

Nobody cares how it looks like while developing. You're learning, you'll become better eventually.

Sign up to request clarification or add additional context in comments.

1 Comment

I feel like I am close I tried: def get_user_num(user_num1, user_num2): print('FIXME: Finish get_user_num()') but still not working
2

I found the solution!!! Thank you all for the help. It really did just take trial and error and making sense of the error messages.

'''

def get_user_num():
    print('FIXME: Finish get_user_num()')
    return -1
    
def compute_avg(user_num1, user_num2):
    print('FIXME: Finish compute_avg()')
    return -1


user_num1 = 0
user_num2 = 0
avg_result = 0

user_num1 = get_user_num()
user_num2 = get_user_num()
avg_result = compute_avg(user_num1, user_num2)

print('Avg:', avg_result)

'''

1 Comment

"It really did just take trial and error and making sense of the error messages." Hehehehe, you've just defined the modern programming as we know it, just add a little bit of reading the manual and perhaps sketching of the problem on a piece of paper. Try to go through these while learning Python: 1, 2, 3 and 4 in that order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.