#๐Ÿ”’ doctest

128 messages ยท Page 1 of 1 (latest)

wintry bolt
#

doctest help

uneven valveBOT
#

@wintry bolt

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.

wintry bolt
#

@rancid ice

#

is the setting here?

rancid ice
#

notice my arrows

wintry bolt
#

sorry about that

rancid ice
#

no worries

wintry bolt
#

is this the correct setting?

rancid ice
#

pycharm is a specialist tool, it is not meant to be beginner friendly

rancid ice
#

you had an example of a different format earlier

#

so look into what those sepcific styles are

#

restructured text, numpy and googles format are the three most used styles

wintry bolt
#

it's just for my exact

#

exam

#

i hate writing the test cases

uneven valveBOT
#

Hey @wintry bolt!

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.
rancid ice
#

no, it would probably not have that

wintry bolt
#

and i got the indentation wrong, which made it not work, and i had limited time

rancid ice
#

use multi carret edit to make quicker changes

wintry bolt
#

for creating doctests

#

to make sure the formatting is correct?

rancid ice
#

probably not easier, maybe faster

#

i dont know the format you want to write

wintry bolt
#

okayy, that's fine then

#

tysmm for ur help

#

๐Ÿ™

#

this one works pretty well, and is close to the example i sent

rancid ice
#

it is pretty close

#

what more do you have to add? can you do it for this example so i can see?

#

if you dont mind ofc @wintry bolt

wintry bolt
#

so one that did

rancid ice
#

alright... want to see how i would do it?

wintry bolt
#

"""
Description
Args
Returns
Raises

Examples

#

does all the formatting

#

and stuff for me

#

i just have to type my info

wintry bolt
wintry bolt
rancid ice
#

do you know why >>> is shown as part of the example?

wintry bolt
#

not exactly

rancid ice
#

that is the python REPL

#

or python shell

#

it lets you run code, one line at the time

wintry bolt
#

okay

rancid ice
wintry bolt
#

i have this one

#

i can delete the current doctest i have

rancid ice
#

share the text here please

#

!code

uneven valveBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

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

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

rancid ice
#

ill copy paste it and show you how i would do it

wintry bolt
#
def need_to_buy_ticket(age: float, height: float) -> bool:
    """
    Determine whether a child needs to buy a ticket to enter a park.

    Args:
        age (float): The age of the child in years.
        height (float): The height of the child in centimeters.

    Returns:
        bool: True if the child needs to buy a ticket, False otherwise.

    Rules:
    - A child aged 6 or younger does not need to buy a ticket.
    - A child taller than 120 cm must buy a ticket, regardless of age.

    Examples:
        >>> need_to_buy_ticket(6, 119.9)
        False
        >>> need_to_buy_ticket(6, 121)
        True
        >>> need_to_buy_ticket(5.5, 122)
        True
        >>> need_to_buy_ticket(7, 115)
        True
        >>> need_to_buy_ticket(3, 100)
        False
    """
    # Precondition checks (ensure input is float or int)
    assert isinstance(age, (int, float)), "Age must be an int or float."
    assert isinstance(height, (int, float)), "Height must be an int or float."

    # Determine ticket requirement
    return height > 120 or age > 6


if __name__ == "__main__":
    import doctest
    doctest.testmod()
rancid ice
#

here is my REPL

#

you get there by writing python in your terminal and press enter

#

i have a custom repl called ptpython it does different things for me, no need to worry about that.

wintry bolt
#

wait

#

so

rancid ice
wintry bolt
#

all i'd have to do is write python in my term?

rancid ice
#

and now i run the code

rancid ice
#

and now i can copy paste the output of my terminal to my code

wintry bolt
# rancid ice

a repl is just somewhere to quickly test code right?

rancid ice
#
"""
>>> need_to_buy_ticket(6, 119.9)
False

>>> need_to_buy_ticket(6, 121)
True

>>> need_to_buy_ticket(5.5, 122)
True

>>> need_to_buy_ticket(7, 115)
True

>>> need_to_buy_ticket(3, 100)
False
rancid ice
#

yes, i use it all the time to run and test code

#

you are inside python at this point

wintry bolt
rancid ice
rancid ice
#

the reason why people use this format as an example is because this is what you litterly do and see in the REPL

wintry bolt
#

because i haven't learned about it yet

rancid ice
wintry bolt
#

yup

rancid ice
#

the app is called windows terminal or just Terminal

#

there are two default shells on windows

wintry bolt
#

ohh

rancid ice
#

command prompt 40 year old system

wintry bolt
#

the windows terminal

rancid ice
#

and Powershell new and cool

#

but windows does not update Powershell for you, so you have to get it in windows store or using winget

wintry bolt
#

it seems i have it

rancid ice
#

you have windows powershell

#

or Blue Powershell

#

Microsoft is bad at naming things

#

so both windows powershell and powershell are the same app, just different versions

wintry bolt
#

ahhh

#

icic

rancid ice
#

if you trype python and press enter you will go into the REPL

#

you exit the repl with exit()

wintry bolt
#

okok icic

rancid ice
#

you can check out help in the repl as well

wintry bolt
#

would i even be able to access

#

the terminal on an exam computer

rancid ice
wintry bolt
#

for computer science?

rancid ice
#

ask about it

rancid ice
wintry bolt
#

okok tysm for ur help ๐Ÿ™

#

is there anyway i can get ur linkedin?

rancid ice
#

but now you know more!

wintry bolt
rancid ice
#

thank you

wintry bolt
#

just lmk when u add it so i can del the msg

rancid ice
#

no worries, got you coverd

wintry bolt
#

okay thank you sm iโ€™ll prolly be in this serber sgain ngl needing help ๐Ÿ˜ญ๐Ÿ˜ญ

rancid ice
#

come and ask whenever you are stuck

#

we are here to help people learn programming, learn python and get good at software engineering

uneven valveBOT
#
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.