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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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