Taller 2
Taller 2
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.
6
Create a class that inherits from User called User_v2.
• Add an attribute called login_attempts.
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
• 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.
• 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.
Note: All the classes must be in another file and have to be imported to be used.
2024