Info

In addition to floating-point values, Python provides formatting specifiers for integers and strings. For example, the following code shows how to use the d formatting specifier to format an integer print ' I worked d hours this week.' hours This code will display the following Here is an example that formats two integer values print 'We have d dogs and d cats.1 (dogs, cats) This code will display We have 2 dogs and 3 cats. Here is an example of how the s formatting specifier can be used to...

Using a Sentinel

The county tax office calculates the annual taxes on property using the following formula property tax property value X 0.0065 Every day, a clerk in the tax office gets a list of properties and has to calculate the tax for each property on the list. You have been asked to design a program that the clerk can use to perform these calculations. In your interview with the tax clerk, you learn that each property is assigned a lot number, and all lot numbers are 1 or greater. You decide to write a...

The while Loop a Condition Controlled Loop

CONCEPT A condition-controlled loop causes a statement or set of statements to repeat as long as a condition is true. In Python you use the while statement to write a condition-controlled loop. The while loop gets its name from the way it works while a condition is true, do some task. The loop has two parts (1) a condition that is tested for a true or false value, and (2) a statement or set of statements that is repeated as long as the condition is true. Figure 5-1 shows the logic of a while...

Python Formula Average Miles Per Gallon

76 Create an instance of the MyGUI class. 12-25 Window displayed by Program 12-1 3 12-25 Window displayed by Program 12-1 3 r Option 1 f* Option 2 P Option 3 OK I Quit r Option 1 f* Option 2 P Option 3 OK I Quit 12.15 You want the user to be able to select only one item from a group of items. Which type of component would you use for the items, radio buttons or check boxes 12.16 You want the user to be able to select any number of items from a group of items. Which type of component would you...

Programming Exercises

Employee and ProductionWorker Classes Write an Employee class that keeps data attributes for the following pieces of information Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information Shift number an integer, such as 1, 2, or 3 The workday is divided into two shifts day and night. The shift attribute will hold an integer value representing the shift that the employee works. The...

Review Questions

The_________programming practice is centered on creating functions that are separate from the data that they work on, programming practice is centered on creating objects. is a component of a class that references data. 5. By doing this you can hide a class's attribute from code outside the class. a. avoid using the self parameter to create the attribute b. begin the attribute's name with two underscores c. begin the name of the attribute with private d. begin the name of the attribute with...

Designing a Program to Use Functions

CONCEPT Programmers commonly use a technique known as top-down design to break down an algorithm into functions. Flowcharting a Program with Functions In Chapter 2 we introduced flowcharts as a tool for designing programs. In a flowchart, a function call is shown with a rectangle that has vertical bars at each side, as shown in Figure 3-8. The name of the function that is being called is written on the symbol. The example shown in Figure 2-8 shows how we would represent a call to the message...

More About Data Output

When this statement executes, it displays Python recognizes several escape characters, some of which are listed in Table 2-7. Table 2-7 Some of Python's escape characters n Causes output to be advanced to the next line. t Causes output to skip over to the next horizontal tab position. Causes a single quote mark to be printed. Causes a double quote mark to be printed. Causes a backslash character to be printed. The t escape character advances the output to the next horizontal tab position. A tab...

Nested Decision Structure Can Be Used To Test More Than One Condition

Nested Decision Structures

The flowchart in the figure starts with a sequence structure. Assuming you have an outdoor thermometer in your window, the first step is Go to the window, and the next step is Read thermometer. A decision structure appears next, testing the condition Cold outside. If this is true, the action wear a coat is performed. Another sequence structure appears next. The step Open the door is performed, followed by Go outside. Quite often, structures must be nested inside other structures. For example,...

Software Company Sells A Package That Retails For 99 Python Program

The area of a rectangle is the rectangle's length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same. Scientists measure an object's mass in kilograms and its weight in newtons. If you know rhe amount of mass of an object in kilograms, you can calculate its weight in newtons with the following formula Write a program that asks the user to enter an object's...

Python Write A Program That Asks The User To Enter The Number Of Packages Purchased

Write a program that asks the user to enter the number of packages purchased. The program should then display the amount of rhe discount if any and the total amount of the purchase after the discount. The Fast Freight Shipping Company charges the following rates Weight of Package Rate per Pound Over 2 pounds but not more than 6 pounds 2.20 Over 6 pounds but not more than 10 pounds 3.70 Write a program that asks the user to enter the weight of a package and then displays the shipping charges, 7....

Using IPO Charts

Ipo Charts Programming

An IPO chart is a simple but effective tool that programmers sometimes use for designing and documenting functions. IPO stands for input, processing, and output, and an IPO chart describes the input, processing, and output of a function. These items are usually laid out in columns the input column shows a description of the data that is passed to the function as arguments, the processing column shows a description of the process that the function performs, and the output column describes the...

Hardware and Software

Major Components Computer

The physical devices that a computer is made of are referred to as the computer's hardware. The programs that run on a computer are referred to as software. The term hardware refers to all of the physical devices, or components, that a computer is made of. A computer is not one single device, but a system of devices that all work together. Like the different instruments in a symphony orchestra, each device in a computer plays its own part. If you have ever shopped for a computer, you've...

What Design Technique Can Be Used To Break Down An Algorithm Into Functions

2 5 Call the main function. 2 6 main Program Output with input shown in bold Enter the gross pay 80000.00 Enter Enter the amount of bonuses 20000.00 Enter Contribution for gross pay 4000.00 Contribution for bonuses 1000.00 Firsr, notice rhe global variable that is created in line 3 This variable will be used as a global constant to represent the percentage of an employee's pay that the company will contribute to a retirement account. It is a common practice to write a constant's name in all...