Program to display string and stripping first character using while loop

This blog contain program to accept string from user input. Display string and stripping first character of a string using while loop

First of all, we will create a function called strip(). This function has one argument and the value for the argument is supplied from user input. Statement str = str[1:] will strip first character from a string

def strip(str):
while str:
print(str)
str = str[1:]

Taking user input and supplying it to function

user_input = input('Enter a string: ')
strip(user_input)

Output

Enter a string: Python
Python
ython
thon
hon
on
n

Complete Code

def strip(str):
while str:
print(str)
str = str[1:]
user_input = input('Enter a string: ')
strip(user_input)
Advertisement

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s