printing each letter of a word + another letter - python
Your answer was pretty much on point, all you needed to do was indent the last line, so it prints out reversed_text
each time a letter is added to it.
name = input("Name: ")
reversed_text = ''
last_index = len(name) - 1
for i in range(last_index, -1, -1):
reversed_text += name[i]
print(reversed_text)
Printing randomized letters between every letter in a word
I tried Your code and it seems that the character inserted in front of the string might be caused by a blank space. To avoid inserting the random character at the end just slice the string and add the last character in the return statement:
def addCharacters(string, strength, randomLettersNumbers):
newString = ''
for c in string[:-1]:
letters = ''
for k in range(strength):
letters += random.choice(randomLettersNumbers)
newString += c + letters
return newString+string[-1]+' '
def processSentence(string,strength,randomLettersNumbers):
return "".join([addCharacters(s,strength,randomLettersNumbers) for s in string.split()])
This code should produce the results You're looking for by splitting Your sentence. Than it applies the method individually for each word and adds a space at the end. The join() method rejoins the modified strings.
printing each letter of string same number of times as number of letters
def vertical_strings(string):
"""takes a string and prints each letter on new line repeating each letter for length of word"""
num = len(string)
for char in string:
new = char * num
print new
vertical_strings('hi')
You just have to make minor tweaks in your code
- Since you need to print, have the print on each iteration of the code
How to print each letter on new line
that is simple using enumerate, for example
word="Hello"
for index,letter in enumerate(word,1):
print(index,":",letter)
output
1 : H
2 : e
3 : l
4 : l
5 : o
trying to replace every letter of the alphabet with another letter to print something completely different eg: python ends up to be fhoeyd
I used this one:
list_A = ['w','o','r','l','d']
list_B = ['y','u','c','w','j']
string = 'world'
string_fin = ''
for s in string:
for i, j in zip (list_A, list_B):
if s == i:
string_fin += j
print(string_fin)
How to print out the letters of a word, one on each line, with three asterisks before and after the word
As simple as that:
word = input("Enter a word: ")
print("***")
for letter in word:
print(letter)
print("***")
Related Topics
Issue Skipping Song by Requester
Construct Networkx Graph from Pandas Dataframe
Python Comparing Previous and Next Row Value
Using Regex to Find All Phrases That Are Completely Capitalized
Count Duplicates Between 2 Lists
How to Periodically Execute a Function With Asyncio
How to Get a Value from a Cell of a Dataframe
How to Extract Integer or Float from String
Formatting Datetime Xlabels in Matplotlib (Pandas Df.Plot() Method)
How to Find Duplicate Values in a List and Merge Them
Return the First Key in Dictionary - Python 3
How to Find Last Occurence Index Matching a Certain Value in a Pandas Series
Split a String At Uppercase Letters
Fastest 2D Convolution or Image Filter in Python
How to Get All Days in Current Month
How to Call Python Script on Excel Vba
Django: Calling .Update() on a Single Model Instance Retrieved by .Get()