#๐Ÿ”’ Python Help

66 messages ยท Page 1 of 1 (latest)

daring sonnetBOT
#

@sharp timber

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.

silk phoenix
#

Have you tried running the examples with your function?

sharp timber
#

yeah

silk phoenix
#

what differences do you notice?

sharp timber
#

its missing or it adds an extra arrow and letter

#

but this is my friends code

daring sonnetBOT
#

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.
sharp timber
#

hold up

silk phoenix
#

Don't worry about your friend's code, just focus on yours for now

sharp timber
#

ok

#

but its meant to be the exact same output as the example shows but ive ran out of ideas tbh

silk phoenix
#

compare exactly the first example with yours

#

type in the same text and values

sharp timber
silk phoenix
#

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

sharp timber
#

ok ive edited it alot

silk phoenix
#

there was one tiny change you needed to make

sharp timber
#

really?

#

........

#

ooop

silk phoenix
#

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

sharp timber
#

do

#

i make it -2?

#

or 0

silk phoenix
#

Why are you subtracting 1?

sharp timber
#

im new to python soz..... started 3 days ago

#

๐Ÿ˜ญ

silk phoenix
#

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

sharp timber
#

so do i increment the score by 1

#

soz the start pos

silk phoenix
#

why?

#

don't just guess

sharp timber
#

the shift it?

#

to*

silk phoenix
#

think about what the values represent

#

!e

text = 'abcdefghijk'

start = 2
num = 6
end = start + num

print(text[start:end])
daring sonnetBOT
#

@silk phoenix :white_check_mark: Your 3.12 eval job has completed with return code 0.

cdefgh
silk phoenix
#

This looks good to me

#

it starts at 2 (remember python starts counting from 0)

#

it ends 6 characters later

#

@sharp timber still there?

sharp timber
#

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)

daring sonnetBOT
#

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.
silk phoenix
#

again, don't worry about your friend's code

sharp timber
#
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)
sharp timber
silk phoenix
sharp timber
#

what to edit/change

silk phoenix
#

look at my example, and my code

#

why do you think your slice is displaying 1 extra character?

daring sonnetBOT
#
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.

#

๐Ÿ”’ Python Help