Please help me with simple project for I em begginer!

** I tried with code if and run it but can not show result like in video:**

Repl link:

def gt5(x):
  print(gt5(x))
  x = int(input("x:  "))
  if x > 5:
    return "yay!"
  else:
    return "ok!"

Hi @tmdluu , you seem to have some problems with your code. Let me help you fix it.
Original code:

def gt5(x):
  print(gt5(x))
  x = int(input("x:  "))
  if x > 5:
    return "yay!"
  else:
    return "ok!"

On the second line, you print the function. This won’t do anything, and it’ll not give you any useful data.
Next you aren’t calling gt5() in your code after defining the function. This is essential for your code to run.
Then your code won’t print anything either, because you only have return to give back a value when the function is called, and not an actual print() statement.
Fixed code:

def gt5(x):
  x = int(input("x:  "))
  if x > 5:
    return "yay!"
  else:
    return "ok!"

value = gt5(4) # Example number 4
print(value)
# Or this:
print(gt5(4)) # Faster way, skipping variable assignment

Hope this helps!

5 Likes

To clarify, this will cause a RecursionError.

Also, the x parameter is overwritten and so passing any x into gt5(x) has no effect.

Alternative function #1:

def gt5():
  x = int(input("x: "))
  if x > 5:
    print("yay!")
  print("ok!")

gt5()

Alternative function #2:

def gt5(x):
  if x > 5:
    print("yay!")
  print("ok!")

gt5(7)

inp = int(input("x: "))
gt5(x)
5 Likes

thanks so much for your help, it is really good instruction!

Hi @tmdluu !
Please mark this post as a Solution since it solved your problem.
Thanks!
cc: @Firepup650 @MattDESTROYER

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.