Python An Introduction to Programming by Parker James R
Author:Parker, James R.
Language: eng
Format: epub
Publisher: Mercury Learning and Information
Published: 2016-11-14T00:00:00+00:00
Exercises
1. Define a class named square in which the construct takes the length of the side as a parameter. This class should have a method area() that computes and returns the area of the square.
2. Define a subclass of square named button that also has a location, passed as X and Y parameters to the constructor. A button always has a width of 10. The button class has the following methods:
center() Return the coordinates of the center of the button
label(s) Set the value of a text label to be drawn to s
3. Create a class client. A client is a data-only class that has no methods other than __init__(), but that holds data. In this case the client class holds a name, a category (retail or commercial), a time value (integer), and a service value (integer). All values are established when the instance is created by passing parameters to __init__(). Now create two subclasses of client, one for each category, retail and commercial.
4. Define a class named fraction that implements fractional numbers. The constructor takes the numerator and denominator as parameters, and the class provides methods to add, multiply, negate (make negative), print, and find the reciprocal of a fraction. Test this class by calculating:
14/16 * 3/4
1/2 â 1/4
Bonus: results are reduced to smallest possible denominator.
5. Given the following class:
class value:
def __init__ (self)
self.val = randrange(0,100)
and the initialization:
t = ()
for i in range(0,100):
v = value()
t = t + (v,)
write the code that scans the tuple t and locates the smallest integer saved in any of the class instances.
6. Create a class that simulates a NAND logic gate with three inputs. The output will be 1 unless all three inputs are 1, in which case the output is 0. Every time an input is changed, the output is changed to reflect the new state; thus, methods to set each input and to calculate the result will be needed, in addition to a method that returns the output.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7501)
Robo-Advisor with Python by Aki Ranin(7374)
Offensive Shellcode from Scratch by Rishalin Pillay(5981)
Ego Is the Enemy by Ryan Holiday(4906)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(4771)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4422)
Python for ArcGIS Pro by Silas Toms Bill Parker(4059)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3762)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3477)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3268)
Speed Up Your Python with Rust by Maxwell Flitton(3222)
Liar's Poker by Michael Lewis(3197)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3184)
Extreme DAX by Michiel Rozema & Henk Vlootman(3159)
Agile Security Operations by Hinne Hettema(3111)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3102)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3074)
Cryptography Algorithms by Massimo Bertaccini(2991)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2971)
