Python Forum
Functions & Passing Parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions & Passing Parameters
#1
Hi

Just started to learn coding so I hope this is an easy question for someone else to help with :)

I've written the code below and expect it to return a value to show the value of the bike reducing until it reaches less than 1000. Clearly I am missing something here as it's returning a weird error message that I can't find anything about on Google.

Appreciate any advice to help a newbie out :)
def function_1(bike_value):
    bike_value = 2000
​
    while bike_value > 1000:
        print("£",bike_value)
        bike_value * 0.9
    
    output = print(bike_value)
    
    return output
​
message = function_1
print(message)
Output:
<function function_1 at 0x000000F9C85F2550>
Larz60+ write Jan-17-2021, 04:30 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
Line 12 is wrong. You need to call the function, by including a pair of parentheses after its name and supplying a value for the parameter it takes (inline that you've called bike_value). You're calling a function on line 13 and passing a value there. You'll learn later why being able to assign functions to variables (which is what you're actually doing) is useful.

However, some other things:

1. You've defined your function to return a value on line 10 - the value of output. The function print does not return a useful value; it simply returns None because its job is to print the thing you passed it and has no need to return a value to be used for later computation.

2. Use meaningful names for your functions. function_1 is a poor name, because it doesn't tell you what the function does.
KAShears79 likes this post
Reply
#3
That isn't an error message, that is function_1. To call the function use "function_1(2000)" and remove "bike_value = 2000" from the function.
KAShears79 likes this post
Reply
#4
And line 6, bike_value*.9 does not do anything. It calculates the value but does not assign the result to anything
bike_value = bike_value*.9
would work, as would
bike_value *= 0.9
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Functions with parameters slehee 2 3,120 Oct-20-2017, 07:47 PM
Last Post: slehee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020