#๐Ÿ”’ function code review

35 messages ยท Page 1 of 1 (latest)

bleak dagger
#

Using the file module i have imported Check_product() from
Update_Stocks.py to Check_Customer.py, in Check_product() there is two condition are given, while it runs it reads the two conditions and displays in the output, whereas per condition it should read either one condition, but it fails, i have shared the output.

wicked hazelBOT
#

@bleak dagger

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.

severe badger
bleak dagger
#

pastebin?

tired bear
#

!paste

wicked hazelBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

bleak dagger
#

def check_product():
name = input("Enter the product name:").replace(" ", "")
for date, info in dates.items():
if name in info['product']:
print("The product is present")
else:
print("The product is not present")
# products()

wicked hazelBOT
#

Hey @bleak dagger!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
bleak dagger
#
def check_product():
    name = input("Enter the product name:").replace(" ", "")
    for date, info in dates.items():
        if name in info['product']:
            print("The product is present")
        else:
            print("The product is not present")
    # products()
severe badger
#

And return statements?

bleak dagger
#

how to it bro, can you suggest me

severe badger
#

!return-gif

wicked hazelBOT
#
Print and return

Here's a handy animation demonstrating how print and return differ in behavior.

See also: /tag return

bleak dagger
#

okay bro, here do i need to give name in parameter huh?

severe badger
#

you need to pass data/info between your functions

#

so that it all makes sense

bleak dagger
#

can you explain me bro on passing the data/info

severe badger
#

!e

person = {
"name": "Bob",
"gender": "male",
"age": 24
}

def is_person_male(p):
  if p["gender"] == "male":
    return True
  else:
    return False

def is_person_over_18(p):
  if p["age"] > 18:
    return True
  else:
    return False

print(f"Is person {person["name"]} a male? {is_person_male(person)}")
print(f"Is person over 18? {is_person_over_18(person)}")

Here's a simple example @bleak dagger

wicked hazelBOT
bleak dagger
#

okay bro, i will try it

severe badger
#

!e

person = {
"name": "Bob",
"gender": "male",
"age": 24
}

def is_person_male(p):
  if p["gender"] == "male":
    return True
  else:
    return False

def is_person_over_18(p):
  if p["age"] > 18:
    return True
  else:
    return False

print(f"Is person {person["name"]} a male? {is_person_male(person)}")
print(f"Is person over 18? {is_person_over_18(person)}")
wicked hazelBOT
severe badger
#

There we go

#

I got mixed up in the notations

bleak dagger
#

is there possible to alter my code and send it

severe badger
#

With those 2 functions, I just pass in the variable p that I defined as a parameter in each. And then it returns whatever value I want back from those functions

bleak dagger
#

bro, can you alter my function code and can you send me with crt syntax, next time i wiill keep it as reference bro

severe badger
#

you need to learn how to do these things bro. Its basics

bleak dagger
#

okay bro, i will try with the example bro, if errors occurs how can i contact you

severe badger
#

just update here or open a new thread

bleak dagger
#

okay bro

bleak dagger
#

in parameter you have mentioned p is p refers to dict?

wicked hazelBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.