Q. Write a Python script that traverses through an input string and prints its characters in different lines- two characters per line.
You can understand by Watching video :-
Answer -
a = input("Enter a string = ") for i in range (0 , len(a)+1 , 2 ) : print( a [ i - 2 : i])
Output :-
Enter a string = Path
Pa
th
>>>
Enter a string = Portal
Po
rt
al
>>>
Its answer is wrong
ReplyDeleteIt would be
a = input("Enter a string = ")
for i in range (2 , len(a)+2 , 2 ) :
print( a [ i - 2 : i])
or
a = input("Enter a string = ")
for i in range (0 , len(a), 2 ) :
print( a [ i : i+2])
a = input("Enter a string = ")
Deletefor i in range (2 , len(a)+2 , 2 ) :
print( a [ i - 2 : i])
or
a = input("Enter a string = ")
for i in range (0 , len(a), 2 ) :
print( a [ i : i+2])
Our program is right. Please run that answer in IDLE Python.
DeleteCode= "powerful"
ReplyDeleteFor ch in code :
Print (ch, '~', end=' ')
You have to input from user.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )