Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 6 - Functions - Section 6.12 - Case Study: Generating Random ASCII Characters - Check Point - MyProgrammingLab - Page 192: 6.25

Answer

chr(randint(ord("B"), ord("M")))

Work Step by Step

The function ord will provide the ASCII code of B and M, and the randint function will give a random integer between the ASCII value of B and M, inclusive of both. And char will convert the final ASCII value to the corresponding character. This solution uses the fact that ASCII code contains the alphabets in contiguous order so the character between B and M will also have their ASCII code between the ASCII code of B and M. randint is a function imported from random library of python.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.