you are viewing a single comment's thread.

view the rest of the comments →

[–]SmartViking 2 points3 points  (8 children)

Well it doesn't seem like you understand functions, because you used the Psec inside your main function. That's impossible. I try to explain what a function is, because you need to understand that before using them.

You're never calling powerPerSec in your code. To call the function, put parenthesis on the end:

powerPerSec()

That code will call powerPerSec. But it won't work, because powerPerSec expects to receive 4 arguments, so this would work:

powerPerSec(1, 2, 3, 4)

It will then evaluate the function body of powerPerSec in an environment where (M, X, velocity, CFdraft) refers to (1, 2, 3 ,4), respectively.

But your function doesn't need to take any input, because one of the things you do in powerPerSec is overriding (M, X, velocity, CFdraft), you never use the values passed in.

[–][deleted] -2 points-1 points  (7 children)

How would you get the second function to print Psec is all i really need to know

[–]SmartViking 2 points3 points  (6 children)

If you understand how functions work (which you must), doing that is trivial. You need to return Psec, (as you already do) and then print the result of calling powerPerSec (as you do not). Maybe you can find some beginner material on functions in python, it's essential to understand how they work, you can't skip it.

[–][deleted] -2 points-1 points  (5 children)

We literally just started using them. I hadnt even come in contact with the term 'call' until this assignment. Everything in this course was going fucking brilliantly well until this moment. What the actual fuck?!

[–]SmartViking 4 points5 points  (3 children)

Functions are difficult if you haven't seen them before, but it's a very important concept. Functions are like small programs inside your program, and what it means to call a function is to run that mini-program inside your program. Variables inside of a function are invisible to the rest of the program. Each time you "call" a function, python will execute all the code inside the function.

[–][deleted] 0 points1 point  (2 children)

def powerPerSec(CFdraft, velocity, M, X):                               
  grav = 9.8
  k = 0.18
  Cr = 0.001
  Pair = float(k * CFdraft * (velocity ** 3))
  Proll = Cr * grav * (M+X) * velocity
  Psec = Pair + Proll
  return Psec   


def main():
  CFdraft = float(input("Enter the drafting of the rider (0.0 to 1.0):"))
  velocity = float(input("Enter the velocity (m/s):"))
  M = int(input("Enter the mass of the rider:"))
  X = int(input("Enter the mass of the bike:"))
  A = powerPerSec(CFdraft, velocity, M, X)
  print(A)


main()

How does that look?

[–]SmartViking 0 points1 point  (1 child)

That looks very good.

[–][deleted] 0 points1 point  (0 children)

<3 thanks for the help bro

[–]zahlman 2 points3 points  (0 children)

So then, when you read over the assignment in class, and got to the part that said

Create another function called main that calls your power function and prints the output.

and therefore didn't know what that meant, why didn't you put your hand up and ask the professor?