#πŸ”’ beginner try to do small task

48 messages Β· Page 1 of 1 (latest)

sick tapirBOT
#

@thick tree

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.

thick tree
#

why am I getting wrong output?

normal jackal
#

Whats the expected output?

normal jackal
# thick tree

Can you reshare the code and output as text please?

thick tree
thick tree
# normal jackal Can you reshare the code and output as text please?

let = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
sen = input()
x=[]
for m in sen:
x.append(m)
for i in x:
if i in let:
try:
x[x.index(i)] = let[let.index(i)+1]
except:
x[x.index(i)] = "a"
for j in x:
print(j,end="")

sick tapirBOT
#

Hey @thick tree!

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.
thick tree
#

it is basic cipher

#

but what is the problem

#

hello your name is zaher right?
jfnmp bpvu obmf js zaifs siiht?

normal jackal
#

well the first letter should be correct from h to i

#
>>> let = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
>>> let.index('h')
7
>>> let[let.index('h')+1]
'i'
thick tree
#

so why it printed j

normal jackal
#

that is strange

#

Tried with hello world

#
hello world
ifmmp xpsme
#

that's correct

#

But I got the same result as you with your text input

thick tree
#

ya hello world works fine

muted topaz
normal jackal
#

I'll try my best tho

#

First of all, don't need to append m to x as its redundant

In fact I removed these lines:

for m in sen:
    x.append(m)
#

So x is an empty list and what should be done is to loop through the sen sentence by letter

#

You used i but I set mine to letter so I don't get confused with single character variables

#

for letter in sen

#

I then check if letter in let because we have that ? in the sen so that goes into a else: statement and append that in with x.append(letter)

#

In the if block, we can do the try except and x.append the index of the letter + 1 as shown earlier

#

like so

try:
  x.append(let(let.index(letter)+1])
except:
  x.append('a')
#

2 things to notice between your try except and mine

#
  1. I renamed i to letter in the let.index
#
  1. I removed the x[x.index(i)] with simply appending the letter to x with x.append. Keeps it simple
#

Then after the for loop, I joined the letters into one sentence and check if the result is as expected

#
result = "".join(x)
#

Hope that makes sense @thick tree

thick tree
#

Thanks bro that’s really helpful 🀍

#

I didn’t try your adjustments because I’m out home but it seems logical

normal jackal
#

alright

thick tree
#

But it kinda hurts when there is no idea why the first code not getting expected output

normal jackal
#

Like this

x[x.index(i)] = let[let.index(i)+1]
#

when you should just be x.append it instead

#

especially this bit x[x.index(i)]

#

That just doesn't look right

sick tapirBOT
#
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.