FAQ: Code Challenge: Python Functions - All Operations

#1

This community-built FAQ covers the “All Operations” exercise from the lesson “Code Challenge: Python Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

FAQs on the exercise All Operations

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like
#2

I’m in the Lots of Math part of Python Functions. It’s the last screen before you complete the lesson.

It is asking me to “return the third number printed mod a.” What exactly is this asking me to do?

10 Likes
#3

I had the same question. Mod is short for modulo, which is the % thing.

5 Likes
#5

I was a bit confused by this question. It says the function should print 3 lines and return 1 value - but in the “should print” part of the comments it shows all the values in one row (not just 1 value).

I did eventually get this right by just returning one value, but then it didn’t look like the suggested solution in the comments - so perhaps the phrasing was a bit odd. Or is it just me?

2 Likes
#6

def lots_of_math(a,b,c,d):
first = a+b
second = c-d
third = first*second
print(first)
print(second)
print(third)
return third % a

This is the code I used… is it correct? Not sure if I was supposed to do that. How do I get it all on one line?

#8

Mod means a lot for some of us, can be modules, modifications, moderations so fix this exercise asap because its confusing.

4 Likes
#9

I have a question about Code challenge (Lots of math) task.

The task is the following (among others): Finally, it should return the third number printed mod a.

If it should just return, not print the 4th value, why in the exercise solution there is 4th and 8th numbers present?
IMO, there should be just 3 values printed for the first function call, and 3 for the second.

#10

Recall that the function has three print statements, and on return we print again. That last print will be mod a value, 0.

#11

I have a Problem, if I use this code:

def lots_of_math(a, b, c, d):
		first = a + b
		second = c - d

print (first = a + b)
print (second = d - c)
print (first) * print (second)
return 


print(lots_of_math(1, 2, 3, 4))

I get this Error Message:

  File "script.py", line 9
    return 
    ^
IndentationError: unexpected indent

I tried it with different indentation levels, but the error message stays the same.
I don`t know what went wrong.

#12

The first indentation following the declaration (the def line terminationg with a colon) sets the default indentation level for the entire function. Here, it appears to be eight spaces, or perhaps two tabs. Your function will (try to) run if every line is indented to the same level as the word ‘first’, and each line is using either spaces or tabs, whatever that ‘first’ line is using.

However, the default indentation for the Python editor used in these courses is two spaces. Whenever the editor encounters a colon, it will automatically indent the next line two spaces. In order to be consistent with the code used in the remainder of the course, and to get used to this particular editor, you should re-type the function, making sure to maintain that default level for each line.

When you do so, you will receive no more “indentation” errors, but will encounter a few others.

#13

Thank`s for the reply, I will start over and try to use the default indentation.

#14
>>> a = 6; b = 7
>>> print (first = a + b)
Traceback (most recent call last):
  File "<pyshell#102>", line 1, in <module>
    print (first = a + b)
TypeError: 'first' is an invalid keyword argument for this function
>>>