Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the Python program to include a function named print_random_letter, which will take a string as a parameter, and then randomly choose a character from

Complete the Python program to include a function named print_random_letter, which will take a string as a parameter, and then randomly choose a character from that string and print the letter and its index position in the string. Follow Instructions below.
- Uncomment the line print_random_letter(current_string) in the given code, and define a function by that name
- print a message that tells the user which random letter was selected from the string, and the index position of that letter (see transcript below for examples.)
- ensure that the random letter really is a letter (not a digit, or a space, or a punctuation mark)
- in the event that the string contains no letters, print a message that reads, "Error: The current string has no letters in it."
- Question 1: Suppose we added another function called char_counter that takes two parameters: the current_string, as well as a single character like 'g'. The function would count the occurrences of the the character in the string, and would return an integer with the count. What would the char_counter function call look like?
- Question 2: Is the char_counter function from above fruitful (ie: returns a value) or non-fruitful (aka: a procedure)
- Question 3: Is the print_random_letter from the lab03.py code a fruitful or non-fruitful function?
- Question 4: Why are while loops used in the main function instead of for loops?

Please press:
'C' - to change the string of text
'L' - to randomly choose a letter from the text
'R' - to repeat this menu again
'E' - to end this program
Current string:
012345....10...15...20...25...30...
↓↓↓↓↓↓↓↓↓↓↓‾ ↓‾ ↓‾ ↓‾ ↓‾
Gotta start with something!
Enter your choice: c
Enter the new string: go!!!!
Current string set to: go!!!!
Enter your choice: r
Thank you for running Lab Assignment 4
Please read carefully as our menu options may have changed:
Please press:
'C' - to change the string of text
'L' - to randomly choose a letter from the text
'R' - to repeat this menu again
'E' - to end this program
Current string:
012345....10...15...20...25...30...
↓↓↓↓↓↓↓↓↓↓↓‾ ↓‾ ↓‾ ↓‾ ↓‾
go!!!!
Enter your choice: l
randomly chose the o at index 1
Enter your choice: l
randomly chose the g at index 0
Enter your choice: l
randomly chose the g at index 0
Enter your choice: l
randomly chose the g at index 0
Enter your choice: c
Enter the new string: 1234
Current string set to: 1234
Enter your choice: l
Error: The current string has no letters in it.
Enter your choice: c
Enter the new string: here
Current string set to: here
Enter your choice: l
randomly chose the e at index 1
Enter your choice: m
You must enter C, L, R, or E: r
Please press:
'C' - to change the string of text
'L' - to randomly choose a letter from the text
'R' - to repeat this menu again
'E' - to end this program
Current string:
012345....10...15...20...25...30...
↓↓↓↓↓↓↓↓↓↓↓‾ ↓‾ ↓‾ ↓‾ ↓‾
here
Enter your choice: e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import random currentstring def printrandomletterstring letters char for char in string if charisalp... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual C# An Introduction to Object-Oriented Programming

Authors: Joyce Farrell

7th edition

978-1337102100

More Books

Students also viewed these Programming questions

Question

Who should be involved?

Answered: 1 week ago