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

  Using an abstract class with only pure virtual functions

Using an abstract class with only pure virtual functions, create three small classes unrelated by inheritance---clases Building, Car and Bicycle. Give each class some uique appropriate attributes and behaviors that it does not have in common with oth..

  We have to deal with student pilots

We have to deal with student pilots and airplanes. Students have a unique student id, a name, and a year that students are in. Airplanes have a unique airplane id, model, a cruising range

  Write a program to calculate students average test scores

Write a program to calculate students average test scores

  Reads a set of integers from file

The code in file "hw5-stree.cpp" reads a set of integers from file and inserts them into a binary search tree. You are asked to implement two functions max() and depth() that compute the maximum element and the depth of the binary search tree.

  Program that initializes a 3x4 array

Write a program that initializes a 3x4 array with test data. It then asks the user for a number input, and checks if the number is present in the array

  The rpn calculator program

The RPN calculator program should read the RPN expression as an entire line from stdin.Input will consist of a single line. After completing the evaluation of the expression, the program should print the contents of the entire stack, starting with th..

  Monkey business, a local zoo

Monkey Business, a local zoo, wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 7 array, where each row represents a di..

  Program that asks the user to enter up to 100 integer score

Write a C program that asks the user to enter up to 100 integer scores, which are to be stored in an array. (You should allow the user to terminate input prior to entering all 100 scores.) The program should then display all the scores, ten per line,..

  Build a definition for a class that stores data

Using C++ language, build a definition for a class that stores data about a two dimensional vector. The class has to have mutators and accessors to get and set the x and y values. Make x and y integers. Then overload the operator * so that it retu..

  Calculation of mortgage interest rates

Instruction of pointers and the calculation of mortgage interest rates.

  We base our need to implement composition upon

What criterion, or criteria, should be used to include objects of a class as data members of another class? In other words, what should we base our need to implement composition upon?

  Program which asks the user for due date of next assignment

Write a program which asks the user for due date of the next assignment (hours, minutes). Then print number of minutes between the current time and the due date in format.

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