Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 5, Problem 24PE
Program Plan Intro

Rectangular Pattern

Program plan:

  • • Import turtle module
  • • Declare constant variables “SPEED=0”, “X_VALUE=0”, and “Y_VALUE=0”.
  • • Define function “rect_shape” by passing the variables “m”, “n”, “wid”, “high”, and “color”.
    • ○ Set heading for the turtle.
    • ○ Set the color for the rectangle using the function “fillcolor ()”.
    • ○ Set the pen’s state “turtle.penup ()”.
    • ○ Move the pen to the co-ordinates (m,n).
    • ○ Set the pen’s state “turtle.pendown ()”.
    • ○ Call “begin_fill ()” function (it should be called before drawing a shape).
    • ○ Set pen to move forward “turtle.forward(wid)”.
    • ○ Set pen to move left “turtle.left(90)”.
    • ○ Set pen to move forward “turtle.forward(high)”.
    • ○ Set pen to move left “turtle.left(90)”.
    • ○ Set pen to move forward “turtle.forward(wid)”.
    • ○ Set pen to move left “turtle.left(90)”.
    • ○ Set pen to move forward “turtle.forward(high)”.
    • ○ Call “end_fill ()” function.
  • • Declare a function “drawPattern ()” by passing the parameters “rect_width” and “rect_height”.
    • ○ Call the function “rect_shape” by passing the parameters “X_VALUE”, “Y_VALUE”, “rect_width”, “rect_height”, and “white”.
    • ○ Calculate the “x_mid” value.
    • ○ Calculate the “y_mid” value.
    • ○ Calculate the “wid_mid” value.
    • ○ Calculate the “high_mid” value.
    • ○ Call the function “rect_shape” by passing the variables “x_mid”, “y_mid”, “wid_mid”, “high_mid”, and “white”.
    • ○ Calculate the “x_in” value.
    • ○ Calculate the “y_in” value.
    • ○ Calculate the “wid_in” value.
    • ○ Calculate the “high_in” value.
    • ○ Call the function “rect_shape” by passing the variables “x_in”, “y_in”, “wid_in”, “high_in”, and “black”.
    • ○ Set the pen’s state “turtle.penup ()”.
    • ○ Move the pen to the co-ordinates (X_VALUE,Y_VALUE).
    • ○ Set the pen’s state “turtle.pendown ()”.
    • ○ Move the pen to the co-ordinates (x_in, y_in).
    • ○ Set the pen’s state “turtle.penup ()”.
    • ○ Move the pen to the co-ordinates (X_VALUE + rect_width, Y_VALUE + rect_height).
    • ○ Set the pen’s state “turtle.pendown ()”.
    • ○ Move the pen to the co-ordinates (x_in + wid_in,  y_in + high_in).
    • ○ Set the pen’s state “turtle.penup ()”.
    • ○ Move the pen to the co-ordinates (X_VALUE + rect_width, Y_VALUE ).
    • ○ Set the pen’s state “turtle.pendown ()”.
    • ○ Move the pen to the co-ordinates (x_in + wid_in,  y_in).
    • ○ Set the pen’s state “turtle.penup ()”.
    • ○ Move the pen to the co-ordinates (X_VALUE , Y_VALUE + rect_height).
    • ○ Set the pen’s state “turtle.pendown ()”.
    • ○ Move the pen to the co-ordinates (x_in ,  y_in + high_in).
    • ○ Set the pen’s state “turtle.penup ()”.
    • ○ Move the pen to the co-ordinates (X_VALUE , Y_VALUE + rect_height/2).
    • ○ Set the pen’s state to down position.
    • ○ Move the pen to the specified co-ordinates.
    • ○ Set the pen’s state to up position.
    • ○ Move the pen to the specified co-ordinates (X_VALUE + rect_width, Y_VALUE + rect_height/2).
    • ○ Set the pen’s state to down position.
    • ○ Move the pen to the co-ordinates (x_in + wid_in,  Y_VALUE + rect_height/2).
    • ○ Set the pen’s state to up position.
    • ○ Move the pen to the co-ordinates (X_VALUE + rect_width/2 , Y_VALUE).
    • ○ Set the pen’s state to down position.
    • ○ Move the pen to the co-ordinates (X_VALUE + rect_width/2 , y_in).
    • ○ Set the pen’s state to up position.
    • ○ Move the pen to the co-ordinates (X_VALUE + rect_width/2 , Y_VALUE + rect_height).
    • ○ Set the pen’s state to down position.
    • ○ Move the pen to the co-ordinates (X_VALUE + rect_width/2 , y_in + high_in).
  • • Define a function “main()”.
    • ○ Call the function “speed()”.
    • ○ Call the function “hideturtle()”.
    • ○ Prompt the user to enter the width.
    • ○ Prompt the user to enter the height.
    • ○ Call the function “drawPattern()” by passing the parameter.
  • • Call the main() function.

Blurred answer
Students have asked these similar questions
C++ Visual 2019 A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the highest and lowest score received, then averaging the three remaining scores. Write a program that uses this method to calculate a contestant's score. It should include the following functions: void getJudgeData() should ask the user for a judge's score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five judges. void calcScore() should calculate and display the average of the three scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the five scores. The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the…
Use C Language Airline Reservation System   A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of alternatives:   Please type 1 for "first class" Please type 2 for "economy"   If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of…
Rest of code in image / This is a bad programming style since it is using goto.  // This is an spagetti code and not working.// Use function to display  menu, and display game rules,// Use different color for text display.// fix it so it works any way you like./*HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);    // Write 16 lines in 16 different colors.    for (int color = 0; color < 16; color++)    {        SetConsoleTextAttribute (screen, color);        cout << " Hello World!" << endl;        Sleep(400);   // Pause between lines to watch them appear    }    // Restore the normal text color)    SetConsoleTextAttribute(screen, 7);*/#include <iostream>#include <windows.h>using namespace std;int  main(){    //textbackground(WHITE);    //textcolor(RED);    system("cls");    char ch, a[20], ch2;    int num = 100, rnum, guess, count, ch1, c = 0;    cout << "**********************************************************"<<endl;    cout << "*…

Chapter 5 Solutions

Starting Out with Python (4th Edition)

Ch. 5.4 - What is a variables scope?Ch. 5.4 - Prob. 12CPCh. 5.5 - What are the pieces of data that are passed into a...Ch. 5.5 - What are the variables that receive pieces of data...Ch. 5.5 - Prob. 15CPCh. 5.5 - When a parameter is changed, does this affect the...Ch. 5.5 - The following statements call a function named...Ch. 5.6 - What is the scope of a global variable?Ch. 5.6 - Give one good reason that you should not use...Ch. 5.6 - Prob. 20CPCh. 5.7 - How does a value-returning function differ from...Ch. 5.7 - Prob. 22CPCh. 5.7 - Prob. 23CPCh. 5.7 - What does the following statement do? x =...Ch. 5.7 - What does the following statement do? print...Ch. 5.7 - What does the following statement do? print...Ch. 5.7 - What does the following statement do? print...Ch. 5.7 - What does the following statement do? print...Ch. 5.7 - When the random module is imported, what does it...Ch. 5.7 - What happens if the same seed value is always used...Ch. 5.8 - Prob. 31CPCh. 5.8 - Look at the following function definition: def...Ch. 5.8 - What is a Boolean function?Ch. 5.9 - What import statement do you need to write in a...Ch. 5.9 - Write a statement that uses a math module function...Ch. 5.9 - Write a statement that uses a math module function...Ch. 5 - A group of statements that exist within a program...Ch. 5 - A design technique that helps to reduce the...Ch. 5 - The first line of a function definition is known...Ch. 5 - You___a function to execute it. a. define b. call...Ch. 5 - A design technique that programmers use to break...Ch. 5 - Prob. 6MCCh. 5 - A ______ is a variable that is created inside a...Ch. 5 - Prob. 8MCCh. 5 - Prob. 9MCCh. 5 - Prob. 10MCCh. 5 - A variable that is visible to every function in a...Ch. 5 - Prob. 12MCCh. 5 - This is a prewritten function that is built into a...Ch. 5 - This standard library function returns a random...Ch. 5 - This standard library function returns a random...Ch. 5 - This standard library function returns a random...Ch. 5 - This statement causes a function to end and sends...Ch. 5 - This is a design tool that describes the input,...Ch. 5 - This type of function returns either True or...Ch. 5 - This is a math module function. a. derivative b....Ch. 5 - The phrase "divide and conquer" means that all of...Ch. 5 - Functions make it easier for programmers to work...Ch. 5 - Function names should be as short as possible.Ch. 5 - Calling a function and defining a function mean...Ch. 5 - A flowchart shows the hierarchical relationships...Ch. 5 - A hierarchy chart does not show the steps that are...Ch. 5 - A statement in one function can access a local...Ch. 5 - In Python, you cannot write functions that accept...Ch. 5 - In Python, you can specify which parameter an...Ch. 5 - You cannot have both keyword arguments and...Ch. 5 - Some library functions are built into the Python...Ch. 5 - You do not need to have an import statement in a...Ch. 5 - Complex mathematical expressions can sometimes be...Ch. 5 - A function in Python can return more than one...Ch. 5 - IPO charts provide only brief descriptions of a...Ch. 5 - How do functions help you to reuse code in a...Ch. 5 - Name and describe the two parts of a function...Ch. 5 - When a function is executing, what happens when...Ch. 5 - What is a local variable? What statements are able...Ch. 5 - What is a local variable's scope?Ch. 5 - Prob. 6SACh. 5 - Suppose you want to select a random number from...Ch. 5 - What statement do you have to have in a...Ch. 5 - What three things are listed on an IPO chart?Ch. 5 - What is a Boolean function?Ch. 5 - Prob. 11SACh. 5 - Write a function named times_ten. The function...Ch. 5 - Examine the following function header, then write...Ch. 5 - Look at the following function header: der...Ch. 5 - What will the following program display? def main...Ch. 5 - Look at the following function definition def...Ch. 5 - Write a statement that generates a random number...Ch. 5 - The following statement calls a function named...Ch. 5 - A program contains the following function...Ch. 5 - Write a function named times_ten that accepts a...Ch. 5 - Write a function named get_first_name that asks...Ch. 5 - Kilometer Converter The Kilometer Converter...Ch. 5 - Sales Tax Program Refactoring Programming Exercise...Ch. 5 - How Much Insurance? Many financial experts advise...Ch. 5 - Automobile Costs Write a program that asks the...Ch. 5 - Property Tax A county collects property taxes on...Ch. 5 - Calories from Fat and Carbohydrates A nutritionist...Ch. 5 - Stadium Seating There are three seating categories...Ch. 5 - Paint Job Estimator A painting company has...Ch. 5 - Monthly Sales Tax A retail company must file a...Ch. 5 - Feet to Inches The Feet to Inches Problem One foot...Ch. 5 - Math Quiz Write a program that gives simple math...Ch. 5 - Maximum of Two Values Write a function named max...Ch. 5 - Falling Distance When an object is falling because...Ch. 5 - Kinetic Energy In physics, an object that is in...Ch. 5 - Test Average and Grade Write a program that asks...Ch. 5 - Odd/Even Counter In this chapter, you saw an...Ch. 5 - Prime Numbers A prime number is a number that is...Ch. 5 - Prime Number List This exercise assumes that you...Ch. 5 - Future Value Suppose you have a certain amount of...Ch. 5 - Random Number Guessing Game Write a program that...Ch. 5 - Rock, Paper, Scissors Game Write a program that...Ch. 5 - Turtle Graphics: Triangle Function Write a...Ch. 5 - Turtle Graphics: Modular Snowman Write a program...Ch. 5 - Prob. 24PECh. 5 - Turtle Graphics: Checkerboard Write a turtle...Ch. 5 - Turtle Graphics: City Skyline Write a turtle...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage