#π beginner try to do small task
48 messages Β· Page 1 of 1 (latest)
@thick tree
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.
Whats the expected output?
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="")
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.
is this a caesar cipher?
it is basic cipher
but what is the problem
hello your name is zaher right?
jfnmp bpvu obmf js zaifs siiht?
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'
so why it printed j
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
ya hello world works fine
the x[x.index(i)] confuses me
ok so I kinda fixed it but... not sure how to explain it.
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
- I renamed
itoletterin the let.index
- I removed the
x[x.index(i)]with simply appending the letter toxwithx.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
Thanks bro thatβs really helpful π€
I didnβt try your adjustments because Iβm out home but it seems logical
alright
But it kinda hurts when there is no idea why the first code not getting expected output
a few that I can guess why it didn't work is probably because you were treating the list like a dictionary but it isn't
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
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.