#๐ Python Help
66 messages ยท Page 1 of 1 (latest)
@sharp timber
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.
Have you tried running the examples with your function?
yeah
what differences do you notice?
Hey @sharp timber!
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.
hold up
Don't worry about your friend's code, just focus on yours for now
ok
but its meant to be the exact same output as the example shows but ive ran out of ideas tbh
ok, so now think about what letters you've displayed
7 are showing up instead of 6
so that should tell you that you should look at how you're performing your slice
ok ive edited it alot
there was one tiny change you needed to make
look closely at your slice
start_pos = 2
num_chars = 6
end_pos = start_pos + num_chars
lets say these are the values entered
if the start is 2, and you want 6 characters, then the end is start + num_chars
that part is great
selected_chars = input_string[start_pos - 1:end_pos]
but now look at the slice you're making
Why are you subtracting 1?
no need to apologize, I'm just trying to get you to think critically about the code you write
everything has its place
so it's good to question why things are there
think about what the values represent
!e
text = 'abcdefghijk'
start = 2
num = 6
end = start + num
print(text[start:end])
@silk phoenix :white_check_mark: Your 3.12 eval job has completed with return code 0.
cdefgh
This looks good to me
it starts at 2 (remember python starts counting from 0)
it ends 6 characters later
@sharp timber still there?
yeah......
just trying to figure it out
just trying to comprehend
def connect_chars(text, start, length):
# Slice the text to get the desired substring
sliced_text = text[start:start + length]
# Join the characters of the substring with "->" separator
connected_string = "->".join(sliced_text)
return connected_string
User Input
text = input("Enter some characters: ")
start_pos = int(input("Enter the start position: "))
length = int(input("Enter the number of characters you want: "))
Display the characters connected by "->"
connected_chars_result = connect_chars(text, start_pos, length)
print("Display the characters that are connected by "->":")
print(connected_chars_result)
Hey @sharp timber!
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.
again, don't worry about your friend's code
def connect_chars(text, start, length):
# Slice the text to get the desired substring
sliced_text = text[start:start + length]
# Join the characters of the substring with "->" separator
connected_string = "->".join(sliced_text)
return connected_string
# User Input
text = input("Enter some characters: ")
start_pos = int(input("Enter the start position: "))
length = int(input("Enter the number of characters you want: "))
# Display the characters connected by "->"
connected_chars_result = connect_chars(text, start_pos, length)
print("Display the characters that are connected by \"->\":")
print(connected_chars_result)
ok ok
what are you still unsure of?
what to edit/change
look at my example, and my code
why do you think your slice is displaying 1 extra character?
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.
๐ Python Help