Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a program on python 3.4 and I\'m not sure how to do it In this prog

ID: 3762904 • Letter: I

Question

I am writing a program on python 3.4 and I'm not sure how to do it

In this programming assignment you are going to use the material covered in Chapter 8 More About Strings to write a program called stringreport.py that creates a report about a string entered by the user at a prompt.

Requirements

Request a string from the user using the prompt "Enter a string: " and do the following:

• Determine the length of the entered string and do one of the following:

o If it is zero characters in length output the message "You did not enter anything!" and exit the program.

o If the entered string is one or more characters in length display the following information about the string and exit the program.

§ The length of the string. That is, the number of characters it contains.

§ The first character of the string.

§ The last character of the string.

§ Indicate if the string contains the word "open".

§ Indicate if the string contains only alphabetic letters and spaces.

§ Indicate if it contains only numeric digits.

§ Indicate if the entire string is lower case.

§ Indicate if the entire string is upper case. Note: For the items above that say "Indicate if...", the output is to present a "yes" or "no".

The information is to be formatted in reports that look like the ones presented in the following examples. The labels shown are to be used in your program.

Enter a string: please open my email

Length: 20

First character: p

Last character: l

Contains open: yes

Only alphabetic letters and spaces: yes

Only numeric digits: no

All lower case: yes

All upper case: no

Enter a string: You did not enter anything!

Enter a string: 8675309

Length: 7

First character: 8

Last character: 9

Contains open: no

Only alphabetic letters and spaces: no

Only numeric digits: yes

All lower case: no

All upper case: no

Enter a string: MIZZOU

Length: 6

First character: M

Last character: U

Contains open: no

Only alphabetic letters and spaces: no

Only numeric digits: no

All lower case: no

All upper case: yes

Enter a string: The user selected open 28 times!

Length: 32

First character: T

Last character: !

Contains open: yes

Only alphabetic letters and spaces: no

Only numeric digits: no

All lower case: no

All upper case: no

Explanation / Answer

Program code:


str = input('Enter a string as input: ')
if(len(str) is 0):
    print('You did not enter anything!')
    exit(0)
print('The string you have entered is: ',str)
print('Length: ', len(str))
print ('First character: ', str[0])
print ('Last character: ', str[len(str) - 1])
if(str.count('open', 0, len(str)) > 0):
    print ('String Contains open: yes')
else:
    print( 'String Contains open: no')
if all(x.isalpha() or x.isspace() for x in str):
    print( 'String contains Only alphabets and spaces: yes')
else:
    print ('String contains Only alphabets and spaces: no')
if(str.isdigit()):
    print ('String contains Only numeric digits: yes')
else:
    print ('String contains Only numeric digits: no')  
if(str.islower()):
    print ('All lower case alphabets: yes')
else:
    print ('All lower case alphabets: no')
if(str.isupper()):
    print ('All upper case alphabets: yes')
else:
    print ('All upper case alphabets: no')

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote