#๐ doctest
128 messages ยท Page 1 of 1 (latest)
@wintry bolt
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.
sorry about that
no worries
pycharm is a specialist tool, it is not meant to be beginner friendly
i use reStructuredText myself, pick the one you like
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
yeahh, it doesnt seem like pycharm has that exact format ๐ข
it's just for my exact
exam
i hate writing the test cases
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.
no, it would probably not have that
and i got the indentation wrong, which made it not work, and i had limited time
use multi carret edit to make quicker changes
is there any easier way to do the >>>
for creating doctests
to make sure the formatting is correct?
okayy, that's fine then
tysmm for ur help
๐
this one works pretty well, and is close to the example i sent
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
it's mostly i wanted somehting like this
so one that did
alright... want to see how i would do it?
"""
Description
Args
Returns
Raises
Examples
does all the formatting
and stuff for me
i just have to type my info
yess pls
because this takes SO much tim eduring a 90 min exam
do you know why >>> is shown as part of the example?
not exactly
okay
do you have the function written already?
ill copy paste it and show you how i would do it
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()
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.
all i'd have to do is write python in my term?
and now i run the code
to enter the repl, yes
and now i can copy paste the output of my terminal to my code
a repl is just somewhere to quickly test code right?
"""
>>> 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
it is called Read Eval Print Loop
yes, i use it all the time to run and test code
you are inside python at this point
would it generate the formatting for me at that point?
did not have to write this, only had to run the function examples in my terminal
the text is as i showed above
the reason why people use this format as an example is because this is what you litterly do and see in the REPL
how do i enter the terminal?
because i haven't learned about it yet
windows user?
yup
the app is called windows terminal or just Terminal
there are two default shells on windows
ohh
command prompt 40 year old system
the windows terminal
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
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
if you trype python and press enter you will go into the REPL
you exit the repl with exit()
okok icic
i dont know, i had my exam on pen and paper
for computer science?
ask about it
yeah
i'm gonna email my prof and ask ๐ญ
okok tysm for ur help ๐
is there anyway i can get ur linkedin?
but now you know more!
i don't think i would alearnt this in class either
sure, but its not a thing i use much. i use eivl everywhere
thank you
just lmk when u add it so i can del the msg
no worries, got you coverd
okay thank you sm iโll prolly be in this serber sgain ngl needing help ๐ญ๐ญ
come and ask whenever you are stuck
we are here to help people learn programming, learn python and get good at software engineering
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.