#đź”’ My function not working

86 messages · Page 1 of 1 (latest)

narrow pivot
#

I need to finish a school project and idk why my function ain’t functioning

def mylist ():
my_list[“jake, arnold, mike,”
Return

tawny spearBOT
#

@narrow pivot

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

narrow pivot
#

Like it tells me that it’s an ident error and when I fix it I get 3 new errors

#

Let me fetch the exact code in a second

#

str(input("This is an STR stop point press whatever characters on your keyboard and screen will clear "))
cls()
print("Hello this is a cool program")
def namelist(dagistan, khabib):
print("hi")
name_list = ["Johapp", "Matthew", "Sion"]
return dagistan,

#print(name_list, "\nHello guys")

tawny spearBOT
#

Hey @narrow pivot!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
narrow pivot
#

 str(input("This is an STR stop point press whatever characters on your keyboard and screen will clear "))
cls()
print("Hello this is a cool program")
def namelist(dagistan, khabib):
    print("hi")
name_list = ["Johapp", "Matthew", "Sion"]
return dagistan, 

#print(name_list, "\nHello guys")
viral ridge
#

codeblock is done with backticks, not quotes

#

```

#

and py should be on the same line as the first 3 backticks

#

```py
<code here>
```

#

perfect

#

do you understand what indentation means?

narrow pivot
#

yeah

#

its when there has to be like space but tab

viral ridge
#

What exactly do you want your function to do?

narrow pivot
#

after .

#

:*

viral ridge
narrow pivot
#

ermm

#

idk

#

sorry

#

im not that good at python

viral ridge
#

that's ok, that's why I'm asking, so I can see what you understand already

#

it's not just the first line that must be indented, it's any line that needs to be part of the function

#
def function():
    print("This is in the function")
    print("This is also in the function")
    print("This too is in the function")

print("This is not in the function")
#

can you tell from this which lines are inside the function and which lines are not?

narrow pivot
viral ridge
# narrow pivot

well based on the example I just showed you, is your return inside the function or outside the function?

narrow pivot
#

lol

narrow pivot
#

Tysm

#

hold on let me see if it works now

viral ridge
#

what exactly are you trying to do with your function though?

#

It doesn't really seem to be doing anything meaningful

narrow pivot
#

i have a school project

#

for every class we need to create a python program

#

and this is one of the 8 instructions for ts program :

Create a program that accepts names and adds them to a list - use functions to add, remove and change names (NOTE! no print or input in functions)

#

this is like the third one

viral ridge
#

Your function is not doing what is asked

narrow pivot
#

yeah ik

#

ive not finished everything

#

i get i have to append

#

and stuff

#

and pop

viral ridge
#

Yes, but you should not be creating the list inside the function

narrow pivot
#

oh

#

how then is this possible

viral ridge
#

do you understand what the parameters of a function are for?

narrow pivot
#

my native tongue isnt english could you rephrase that somehow?

viral ridge
#
def function(param1, param2):
#

when you define a function, you can also provide "parameters" inside the ()

#

these are "required information" for the function to do its job

narrow pivot
#

no im not very informed over what they are for

viral ridge
#

do you know how to calculate the area of a rectangle?

#

not in code, just in general

narrow pivot
#

erm

#

b*h

viral ridge
#

exactly

#

we could make a function for that

narrow pivot
#

okay

viral ridge
#
def get_rectangle_area(b, h):
    return b * h
#

the parameters are b and h

#

you couldn't calculate the area with just b or just h, you need both

#

so this tells the function that when we need to use it, you must provide those 2 values

#

!e

def get_rectangle_area(b, h):
    return b * h

print(get_rectangle_area(10, 5))
tawny spearBOT
viral ridge
#

when we use the function, it's known as "calling" the function

#

I gave it 2 values. 10 and 5

#

python is smart enough to know that 10 is b and 5 is h

narrow pivot
#

yeah

viral ridge
#

ok, so instead, we could make a function that "adds something to a list"

#

instead of b and h

#

the parameters would be "the list we want to add something to" and "the thing we want to add to that list"

#
def add_to_list(a_list, value):
#

I'm really sorry but I have to go! Hopefully that's enough info to get started with!

narrow pivot
#

wait a min

#

ok

#

np

#

tysm for all ur hel

#

help

viral ridge
#

np!

narrow pivot
#

its appreciated

tawny spearBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.