Sumit S.
asked 10/09/18Write a program script that traverses through an input string and prints its characters in different lines -- two characters in a line
1 Expert Answer
Eddie B. answered 03/20/19
Purdue University student studying computer engineering
I believe you are asking for a program to read an input string then output the string two characters at a time on separate lines. If so, then this should do the trick:
inputString = input("Please type your string: ")
i = 0
while i < len(inputString):
print(inputString[i] + inputString[i + 1])
if((i + 3) == len(inputString)):
print(inputString[i + 2])
break
i = i + 2
Depending on the console running the program, you may need to add "\n" to the beginning of the print statements so that the read print("\n" + inputString[i] + inputString[i + 1]) and print("\n" + inputString[i + 2])
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Rummy B.
string=input("Enter your string:") for a in range(2): for b in range(1,3): print(string,end=' ') print()11/04/18