We can combine assignment statements

Assignment Help C/C++ Programming
Reference no: EM13168104

We can combine assignment statements, for-loops, and if statements to perform a wide range of tasks with lists. Suppose we have a bookstore with each book defined as follows:Book = namedtuple('Book', 'author title genre year price instock'), where "genre" is the category of book (e.g., cookbook or mystery or sports), "year" is the year of publication, and "instock" is the number of copies of that book we have available to sell. Make up a half-dozen Book structures and combine them into a list called BSI (for "book store inventory").

(e.1) Write a sequence of statements that prints the title of each book in BSI, one per line.

(e.2) Write a sequence of statements that prints the title of each book in BSI, one per line, in alphabetical order; do this without changing the original order of BSI.

(e.3) Write a sequence of statements that raises the price of each book in BSI by 10%; this does change the value of BSI.

(e.4) Write a sequence of statements that prints the title of each book in BSI whose genre is Technology.

(e.5) If we ask how many books there are in our list BSI, there are two possible answers: One is just the number of items in the list, each representing a different author/title combination (book publishers call this the number of "titles"); the other is the number of individual, physical books in the store's inventory (i.e., the sum of all the instock figures of all the "titles" in the list).

Write a sequence of statements that creates a new list containing the Books ("titles") in BSI that were published before 2000 and a second new list of Books published in 2000 or later. Then write a sequence of statements that prints one of these phrases: More titles before 2000 or More titles 2000 or later. Finally, add to whichever message you print the number of titles in each category, in a form like this: More titles 2000 or later (345 vs. 189). [Hint: To create a new list in this way, start with an empty list. Then, each time you find a new Book that belongs on the list, add that Book to the list. When you've gone through the original list, your new list will have the Books you want. Second hint: There's a simple predefined function that will tell you the number of Books on a (newly created) list.]

(e.6) The value of the inventory of a particular book is the price of that book times the number of copies we have in stock. Write a function called inventory_value that takes a Book as its argument and returns the value of our inventory of that book. Then write a function called top_value that takes a list of Books as its argument and returns the Book object (from the list) that has the highest-vaue inventory. Finally, write a sequence of statements that prints a line in this form: The highest-value book is War and Peace by Tolstoy, Leo at a value of $ 595.00.

(f) Write a series of tkinter statements to draw a face, with a mouth, a nose, and two eyes. Use your eye-drawing code from last week's lab. But don't just copy those lines twice! Even if you use copy and paste to avoid tedious retyping, duplicate code is always a problem: It makes the program longer, and if you have to change it, you have to change every copy. If you skip changing one copy of the duplicate code, your program becomes an inconsistent mess. Happily, we've learned how to avoid writing duplicate code in this situation: We design a function called draw_eye to contain our eye-drawing code; then we call that function twice, once for each eye. But there's one more step, because we don't want to draw both eyes in the same place. Our draw_eye function needs parameters that specifies the starting point for the drawing; then we can call it twice, one with a starting point that's offset from the other.

Write a function called draw_face that calls functions (that you also write) called draw_eye, draw_nose, and draw_mouth. Your nose and mouth don't have to be as fancy as your eyes; in fact, make them as crude and simple as you can to start with, and only refine them if you have time. Include at least two calls to draw_face in your lab3.py file.

(If you're feeling ambitious and have the time, parameterize other aspects of your feature-drawing functions so you can easily draw faces with different-color eyes, different-sized noses, and so on.)

Reference no: EM13168104

Questions Cloud

The total volume of the gas bags of the german dirigible : the total volume of the gas bags of the german dirigible hindenberg, was 2.0 * 10^5m^3. how many grams of H2 would be required to fill them at 20 celcius and 1.00 atm pressure? hint convert m^3>cm^3>mL>L.
Using netbeans, use repetition to display a table of values : Using Netbeans, use repetition to display a table of values showing x, the square of x and the cube of x. X is to go up to 5.
When we sort a list of items, we need a basis : When we sort a list of items, we need a basis on which to compare the items to see whether one is bigger than another. If it's a list of numbers, Python just compares the numeric values; if it's a list of strings, Python compares the strings alpha..
The heating element of a water heater in an apartment : The heating element of a water heater in an apartment building has a maximum power output of 28 kW. Four residents of the building
We can combine assignment statements : We can combine assignment statements, for-loops, and if statements to perform a wide range of tasks with lists. Suppose we have a bookstore with each book defined as follows: Book = namedtuple('Book', 'author title genre year price instock') , wher..
Write a script that simulates a casino machine : Write a script that simulates a casino machine. To play a single round on the machine user pays $ 5. Now when the user start the machine, the machine rolls a pair of dice (simulate both dice with help of random number generator) and user only wins..
A computer has a cache, main memory, and a disk : A computer has a cache, main memory, and a disk. If a referenced word is in the cache, 20 ns are required to access it. If it is in main memory but not in the cache (called cache miss)
A computer has a cache, main memory, and a disk : A computer has a cache, main memory, and a disk. If a referenced word is in the cache, 20 ns are required to access it. If it is in main memory but not in the cache (called cache miss)
The computer game function collision : The computer game function collision () checks whether two circular objects collide; it returns True if they do and False otherwise. Each circular object will be given by it's radius and the (x,y) coordinates of it's center.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

  You have just upgraded your system

You have just upgraded your system to a "fast and wide" SCSI interface. This system has a floppy disk, a CD-ROM and five 8-gigabyte fixed disks. What is the device number of the host adapter? Why?

  Stores a series of numbers in a binary tree.

Queue Converter, Write a program that stores a series of numbers in a binary tree. Then have the program insert the values into a queue in ascending order. Dequeue the values and display them on the screen to confirm that they were stored in the prop..

  Create a class named gamer that has a field for name

Create a class named Gamer that has a field for name(string) and a field for points(int).

  Create a program that displays the number of days in a month

Create a program that displays the number of days in a month. Use a 12-element one-dimensional array to store the number of days in each month (use 28 for the number of days in February).

  Design customized mailing lists for marketing department

Marketing department requires to be able to design customized mailing lists, to send different messages to different types of donors. What system will best meet these requirements?

  Write a c program to compute dr if f1=50 lb and f2 = 4000

make a program for:A hydraulic lift as shown below from fluid mechanics, it can be shown that a small force F1     acting over a piston of diameter D 1    can be multiplied into a large force   F 2    acting over a piston of diameter D 2  .

  Implement a simplified version of the set class

You will implement a simplified version of the set class. You must implement all functions defined in the provided file set.h. You may add other member functions and variables as necessary.

  Use functional decomposition to solve

Use functional decomposition to solve this problem, and code the solution using functions wherever it makes sense to do so. Your program should check for invalid data such as nonpositive dimensions, number of rooms less than 1.

  Write a program that displays a weekly payroll report

Write a program that displays a weekly payroll report

  Assessment system of a university

Write a program for Assessment system of a University

  Random permutations

Write a program in C++ that gives a prompt to the users, asking for an integer M.It then prints out a M different random permutations, one on each of M lines, of the numbers 1, 2, ... , 10, separated by spaces or tabs.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd