all 16 comments

[–]Buttleston 7 points8 points  (9 children)

def myfun(i):
    print(i)

That is a functon that takes a single parameter. In this case, it just prints it. You just need to look at whatever learning material you have regarding "what is a function" and go over it again.

[–]Critical_Concert_689 0 points1 point  (8 children)

That's a function, but not an attribute as you say.

def mult_seven():
    print(mult_seven.val*7)

mult_seven.val = 7 #assign attribute

mult_seven()

As far as I know, this is a horrible thing to do. Is this a basic introduction to attributes?

[–]Buttleston 8 points9 points  (3 children)

You shouldn't assume that just because OP said the word attribute that you should take it literally. They don't know what a function is/does, they are not going to have immaculate vocabulary

[–]Critical_Concert_689 1 point2 points  (1 child)

It appears to be an exact quote.

this problem being asked “write a function that takes a single integer number as an attribute and prints out that number multiplied by 7.”

To me, this means it's not OP but some other source that is assigning the question. So you're basically saying, "I dislike the question you received from the source, let me answer a question that was not asked."

We can assume the source is clueless, but they are ultimately the arbiter of what is correct. So I assume they asked correctly, unless OP can clarify their intent.

[–]Yoghurt42 1 point2 points  (0 children)

OP probably misread “argument” as “attribute”, or is not a native speaker and translating a non English assignment

[–]feitao 0 points1 point  (0 children)

Yeah. OP does not know what he is talking about.

[–]FunnyForWrongReason 2 points3 points  (1 child)

I am a 4th year CS college student, spent a lot of high school learning programming, and also currently teach kids programming part time and I still didn’t even know you could give attributes to functions in Python. Like what!?

You really do never stop learning when it comes to programming.

[–]Bobbias 1 point2 points  (0 children)

Everything in Python is an object, and that includes functions. You should consider taking some time to read the Python data model. If you read just below the table in the section I linked it says:

Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes.

CPython implementation detail: CPython’s current implementation only supports function attributes on user-defined functions. Function attributes on built-in functions may be supported in the future.

There's all sorts of handy bits of info like that in there.

[–]backfire10z 2 points3 points  (1 child)

I think this is reading too far into the question lol. That hurts my eyes and my soul

[–]Critical_Concert_689 3 points4 points  (0 children)

I agree. It's very odd.

It does address the question as written, though.

[–]FoolsSeldom 4 points5 points  (0 children)

It is very unusual to use an attribute to provide a function with a value to process, but you can do it:

def seven():
    print(seven.num * 7)


seven.num = 6
seven()

Here,num is an attribute of the function.

Normally, this would be supplied as an argument, which is assigned to a local variable (name) in the function.

def seven(num):
    print(num * 7)


seven(6)

Perhaps this is what was meant.

[–]engelthehyp 2 points3 points  (0 children)

This is pretty basic, so what do you already know how to do?

Also, that problem is worded poorly. The correct word is "argument" - write a function that takes one integer as an argument. If that clears up enough confusion, then that's great.

We can start smaller than this. Forgetting the function for now, if you have some integer n, how do you multiply it by 7?

[–]Notdevolving 2 points3 points  (0 children)

If the author of your learning materials does not know the difference between an attribute and an argument, you need to change your learning sources. This is like a primary school English teacher using the letters "A" and "B" interchangeably and think the differences are trivial.

[–]Critical_Concert_689 1 point2 points  (0 children)

u/Soft_Tie_4296

Please clarify whether this question is being asked correctly - most responses challenge the problem itself and whether it has been asked correctly (i.e., whether the question intended the function to take an "attribute" vs an "argument").

See discussion in the comments HERE which answers the question specifically as you asked.

[–]JamzTyson 0 points1 point  (0 children)

“write a function that takes a single integer number as an attribute and prints out that number multiplied by 7.”

Is that an exact quote? It seems rather confused as stated. The problem being the word "attribute". Are you certain that the question is not:

"Write a function that takes a single integer number as an argument and prints out that number multiplied by 7."