Introduction to Programming using Python 1st Edition

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

Chapter 6 - Functions - Programming Exercises - Page 211: 6.37

Answer

code

Work Step by Step

# 6.37 (Turtle: generate random characters) Use the functions in RandomCharacter # in Listing 6.11 to display 100 lowercase letters, fifteen per line, as shown in # Figure 6.11a. import turtle from random import randint def getRandomCharacter(ch1, ch2): return chr(randint(ord(ch1), ord(ch2))) # Generate a random uppercase letter def getRandomUpperCaseLetter(): return getRandomCharacter('A', 'Z') def main(): turtle.penup() turtle.forward(-100) turtle.pendown() x = turtle.xcor() y = turtle.ycor() for i in range(100): c = getRandomUpperCaseLetter() turtle.write(c) turtle.penup() turtle.forward(30) turtle.pendown() if (i + 1) % 15 == 0: turtle.penup() turtle.goto(x, y - 30) turtle.pendown() x = turtle.xcor() y = turtle.ycor() turtle.done() main()
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.