Oct-29-2018, 10:18 PM
Hello, I am trying to write a Python program to do the following:
a. Ask the user to enter a str containing at least 6 characters. Assign the str entered to a variable mystr.
b. If mystr has less than 6 characters print ‘<mystr > is not a valid str.’
c. Otherwise, if mystr consists of only alphabetic characters print ‘You have entered a valid alphabetic string.’
d. Otherwise, do the following:
i. print a statement: ‘<myint> is a valid non-alphabetic str.’
ii. Find the index of the first occurrence of ‘e’ in mystr and print this value with a suitable message. A value of -1 indicates mystr does not contain ‘e’.
I have started with:
mystr = input('Enter a str containing at least 6 characters: ')
However, I am unable to figure out the if statement that follows this that counts the number of characters and if it is less than 6, to print the respective message. I am getting a syntax.
a. Ask the user to enter a str containing at least 6 characters. Assign the str entered to a variable mystr.
b. If mystr has less than 6 characters print ‘<mystr > is not a valid str.’
c. Otherwise, if mystr consists of only alphabetic characters print ‘You have entered a valid alphabetic string.’
d. Otherwise, do the following:
i. print a statement: ‘<myint> is a valid non-alphabetic str.’
ii. Find the index of the first occurrence of ‘e’ in mystr and print this value with a suitable message. A value of -1 indicates mystr does not contain ‘e’.
I have started with:
mystr = input('Enter a str containing at least 6 characters: ')
However, I am unable to figure out the if statement that follows this that counts the number of characters and if it is less than 6, to print the respective message. I am getting a syntax.