Write a simple python program to take input from user calculate it's the length and print it in abbreviation form with a full stop after each character. For example, if the user inputs his name as abc then the output produced have to be a . b . c .
Answers
The python program to take input from user calculate it's the length and print it in abbreviation form with a full stop after each character is as follows:
- s=input()
- for i in range(len(s)):
- print(s[i],'.',end=' ')
- The first line takes a string as an input and stores it in the variable s.
- The second line runs a loop which inceases the value of i by one successively until the value of i is less than the length of the string s.
- The third line prints individual charaters and a '.'
Program 1 (Using list and join functions directly):
string = list(input())
print(' . '.join(string)+' . ')
Explanation:
input() takes a string as an input and it is furtherly converted into a list by splitting each letter in it as an element.
As in, the first statement turns 'abc' into ['a', 'b', 'c']
Then, join() joins each element in the list with the string mentioned i.e., ' . ' in between.
So, ' . '.join(string) makes ['a', 'b', 'c'] to a . b . c and we add ' . ' at the end in default, making the string a . b . c .
Program 2 (Using loop):
string=input()
for i in string:
print(i, end=" . ")
Learn more:
1) Printing all the palindromes formed by a palindrome word.
brainly.in/question/19151384
2) Indentation is must in python. Know more about it at :
brainly.in/question/17731168