Define and use functions
Playing with strings
Run Python IDLE or WingIDE to create a new python file and save it under the name YOURNAME-Lab8.py Reaplce YOURNAME with you actual name.
You need to review our lecture slides and check this Website to learn the different operations of the string.
Function 1: main function
Define a string variable under the name UserString and then ask the user to input a value for it through the keyboard.
Call the function HowManyAs defiend below and pass to it the UserString, then print the returned result.
Call the function ShortOrLong defiend below and pass to it the UserString, then print either short or long based on the returned result.
Call the function StringReversed defiend below and pass to it the UserString.
Function 2: How Many As
Write a function called HowManyAs that recieves one string parameter, the function counts and then returns back the numbers of A or a inside the string.
Function 3: Short Or Long
Write a function called ShortOrLong that recieves one stringparameter and it returns back one value. The function recieves a string value and then it returns
True if the length of the passed parameter is less than 5 characters and it returns False if its length is longer than 5 characters.
Function 4: String Reverse
Write a function called StringReversed that recieves 1 parameter which is a string and it returns back one value. The function gives back the reverse of the passed parameter.
--- Run example ---
Enter a string: Alice is Alex friend, she is 29 years old
The string has 3 A.
The sting is long.
The reversed string is: dlo sraey 92 si ehs ,dneirf xelA si ecilA
Program Prolog
For every of the the problem above, provide your solution in a file with the comment and prolog provided explaining your information and the program details:
# supply program prolog
# Prolog
# Author: Mary Smith
# Email: Mary.Smith@uky.edu
# Section: 00
# Date: 8/31/16
'''
Purpose: ....
Preconditions: ....
Postconditions: ....
'''
Requirments:
1- You have to build four different functions (HowManyAs(), ShortOrLong(),StringReversed()) also you need to have the main function.
2- Choose names for your variables that make sense, do not use short names consist of one letter. Use good, multi-character, meaningful identifiers (variables) names.
2- Your output should match the run examples provided with the problems above.
3- Document your work by putting comments at the top of your program, remember that comments in python are either:
starts with # in case the comment is one line only or ''' and ''' if the comment is taking more than one line.
4- At the top of your program, you should have a prolog (name, date, etc.)
5- Save the solution for this lab in a file (strings_your_name.py).
When you are done with the lab, show your file to the instructor, sign the lab sheet, and then submit your solution on CANVAS under lab8.