0

this prints all five iterations. cani make it only print the last iteration?

key1 = [' ','a','b','c','0','1','2','3']
out = ''
inpt = raw_input('enter text:')

for i in inpt:
    if i in key1:
        out = out + key1[key1.index(i)+3]
    print out
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by bmanzana
0

Simply unindent the last line out of the 'for' loop

key1 = [' ','a','b','c','0','1','2','3']
out = ''
inpt = raw_input('enter text:')

for i in inpt:
    if i in key1:
        out = out + key1[key1.index(i)+3]
print out
1

Also you should check the value of this statement
out = out + key1[key1.index(i)+3]
to make sure that key1.index(i)+3 isn't greater than the length of the list, key1.

0

the keys length dosent really matter right now, this was just a test for functionality. but thank you for the post any way that would have been a valid point. i will try moving the print statement, thanks again. so i ralised what i retard i am why i even had the print function inside the loop to begin with is beyond me. i was tired when i started this and had just finished an alpha only encryption program and was wanting to move to alpha numerics and fill spaces with somthing other than white space. so any way thanks for pointing that out, i feel retarded lol

Edited by bmanzana: realized how stupid i was

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.