Home > database >  Why is my def function not working in python?
Why is my def function not working in python?

Time:12-14

Hello I am new to python and I am having an issue with this function. Basically I’m trying to create a card game, and I know I’ve started it wrong anyway according to the question, but I have started doing it this way and I want to finish this before I change it completely. My def function seems to not be working, even when I print it.

This is probably a very small and obvious mistake but I am new, also some of the rest of my code may be wrong obviously. I am using trinket.

enter image description here

enter image description here

enter image description here

Thank you for reading

I tried to print it and return it within the define statement, and redefine the variables. i think this issue maybe be something small that I haven’t learnt, or a larger problem overall in the code.

CodePudding user response:

I can't see the entier of you code from the images. But I think an issue is your "take" variable.

Why does your def card_funct(): have "take" appear twice with out being used?(at least that I can see you do not use it later.) Can you explain what you are wanting this variable to do? From there I could help you better.

also this: for X in range(3): shuffle = input('shuffling')

did you mean to put print()?

If you could copy and paste your code into your questions, for people to play with it helps get answers quicker.

good luck.

CodePudding user response:

The idea of using a function (def) is to code it separatly and call it inside your code when you need it! You would also need to declare the function before calling it (preferably at the beggining of your code).

Example:

def sum_numbers(a,b):
   answer=a b
   return answer

And then you would use it on your code:

a=5
b=6
print(sum_numbers(a,b))

This would print 11 on your screen (even that the "math" is not inside of your code)

  • Related