0% found this document useful (0 votes)
13 views3 pages

Taller 2

The document provides instructions and exercises for a programming assignment involving classes in Python. Students are asked to create several classes, including classes for numbers, circles, restaurants, users, and more. They are also asked to inherit from some of the base classes to create subclasses like Restaurant_v2, User_v2, IceCreamStand, and Admin. The exercises involve writing methods, creating instances, and calling methods of the classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Taller 2

The document provides instructions and exercises for a programming assignment involving classes in Python. Students are asked to create several classes, including classes for numbers, circles, restaurants, users, and more. They are also asked to inherit from some of the base classes to create subclasses like Restaurant_v2, User_v2, IceCreamStand, and Admin. The exercises involve writing methods, creating instances, and calling methods of the classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Universidad Industrial de Santander E3T Programación de Computadores II

Workshop - Parcial 2
(Update April 1, 2024)

Instructions:
To solve these exercises, limit your references to the following two pages:
• https://www.w3schools.com/python/

• https://docs.python.org/3/tutorial/
You also can use Pythontutor to debug your code:
• https://pythontutor.com/python-compiler.html

Classes

1
Write a class called number
• Create one attribute x.
• Write a method pow(n) that calculates the power of the attribute x by the n exponent.

• Create three instances representing different numbers and call the method for each one.

2
Write a class called circle
• The class contain the radius attribute.
• Create one method that returns the area.
• Create one method that returns the perimeter.

• Create two instances representing different circles and call the methods for each one.

3
Create a class called Restaurant.
• The __init__() method for Restaurant should store two attributes: a restaurant_name
and a cuisine_type.
• Make a method called describe_restaurant() that prints these two pieces of information,
and a method called open_restaurant() that prints a message indicating that the restaurant
is open.
• Create three different instances from the class Restaurant.
• Print the two attributes individually and then call both methods.

4
Make a class called User.
• Create three attributes called first_name, last_name and age.

• Make a method called describe_user() that prints a summary of the user’s information.
• Make another method called greet_user() that prints a personalized greeting to the user.
• Create three instances representing different users, and call both methods for each user.

2024
Universidad Industrial de Santander E3T Programación de Computadores II

5
Create a class that inherits from Restaurant called Restaurant_v2.

• Add an attribute called number_served with a default value of 0.


• Add a method called set_number_served() that lets you set the number of customers that
have been served.
• Add a method called increment_number_served() that lets you increment the number of
customers who’ve been served.
• Create an instance from Restaurant_v2 called Mexican. Print the number of customers the
restaurant has served, and then change this value and print it again.

6
Create a class that inherits from User called User_v2.
• Add an attribute called login_attempts.

• Write a method called increment_login_attempts() that increments the value of


login_attempts by 1.
• Write another method called reset_login_attempts() that resets the value of
login_attempts to 0.
• Make an instance of the User class and call increment_login_attempts() several times.
Print the value of login_attempts to make sure it was incremented properly and then call
reset_login_attempts(). Print login_attempts again to make sure it was reset to 0.

7
An ice cream stand is a specific kind of restaurant. Write a class called IceCreamStand that
inherits from the Restaurant_v2 class (Exercise 5).

• Add an attribute called flavors that stores a list of ice cream flavors.
• Write a method that displays these flavors (display_flavors()). Create an instance of
IceCreamStand, and call this method.

8
An administrator is a special kind of user. Write a class called Admin that inherits from the
User_v2 class (Exercise 6).

• Add an attribute, privileges, that stores a list of strings like "can add post", "can delete
post", "can ban user", "can configure security settings" and "can view user activity logs".
• Write a method called show_privileges() that lists the administrator’s set of privileges.
Create an instance of Admin, and call your method.

9
Make a separate file called "functions.py" that contains all your classes.

• Make a IceCreamStand instance and call one of its methods to show that the import state-
ment is working properly.
• Make a Admin instance and call one of the Admin’s methods to show that the import statement
is working properly.

2024
Universidad Industrial de Santander E3T Programación de Computadores II

10
Make a class Die

• Write one attribute called sides, which has a default value of 6.


• Write a method called roll_die() that prints a random number between 1 and the number
of sides.
• Make a 6-sided die and roll it 10 times.

• Make a 10-sided die and a 20-sided die. Roll each die 10 times.
• Create a .txt file that stores the results of each roll die.

11
Create a class called Person.

• Its attributes are: name, age, and ID.


• Create a constructor method, where the data can be empty.
• Setters and getters for each of the attributes.

• The data entries must be validated. (Age must be a positive number, ID has to be a number
with 10 characters).
• show(): Shows the person’s data.
• legal_age(): Returns a logical value indicating if it is older than 18.

Create a class called Account

• Its attributes are: owner (which is a person), amount.


• Create a constructor method, where the data can be empty.
• Setters and getters for each of the attributes.

• The attribute cannot be modified directly, only by entering or withdrawing money.


• enter(amount): An amount is entered into the account, if the amount entered is negative,
nothing will be done. This method creates a .txt file that contains the balance of the account.
• withdraw(amount): an amount is withdrawn to the account. This method creates a .txt file
that contains the balance of the account.
• Print_receipt(): This method creates a .txt file that contains the balance of the account.

Note: All the classes must be in another file and have to be imported to be used.

2024

You might also like