63 203
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #39909 in Python for Jason

Question #39909
So far I have:
x=raw_input("Enter a Sentence :")
i=0
while i <len(x):
i = i + 1
print(x[0:i])
that asks the user for an input and prints out the individual letters. I wanted to perform certain operations for individual characters and I was not quite sure how to refer to each character. For example, if I have a sentence: I like to eat apples how would I refer to the letter: k so that I can, let's say, turn it red using graphics import. (I'm not interested in knowing how to turn it red, just a way so I can refer to individual characters so I can write certain functions with them)
Expert's answer
Answer on Question#39909, Programming, Python
to read:
Lists,
Strings

#x = str(raw_input(&quot;Enter a Sentence: &quot;))
x = &quot;Hello World!&quot;
print x #string line
letters = [letter for letter in x]
print letters #list of letters
#now perform manipulations on list
letters += [&#039; &#039;,&#039;:&#039;,&#039;)&#039;]
#change by index
letters[6] = &#039;w&#039;
#find by value
newX = &quot;&quot; #new sentence
for i in range(len(letters)):
if letters[i] == &#039;o&#039;:
letters[i] = &#039;0&#039;
newX += letters[i]

print newX

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions