80 lines
3.3 KiB
Python
80 lines
3.3 KiB
Python
class basics_004:
|
|
|
|
def decims(self):
|
|
"""Ask the user to enter a number with lots of decimal places. Multiply
|
|
this number by two and display the answer."""
|
|
num = float(input("Ingresa un número con muchos decimales: "))
|
|
print(num*2)
|
|
|
|
def decims_round(self):
|
|
"""Update last program so that it will display the answer to two decimal
|
|
places."""
|
|
num = float(input("Ingresa un número con muchos decimales: "))
|
|
numr = round(num*2, 2)
|
|
print(numr)
|
|
|
|
def square_root(self):
|
|
"""Ask the user to enter an integer that is over 500. Work out the
|
|
square root of that number and display it to two decimal places."""
|
|
from math import sqrt
|
|
num = int("Ingresa un número entero mayor de 500: ")
|
|
root = round(sqrt(num), 2)
|
|
print(root)
|
|
|
|
def pi_round(self):
|
|
"""Display pi (π) to five decimal places."""
|
|
from math import pi
|
|
print(round(pi,5))
|
|
|
|
def circle_area(self):
|
|
"""Ask the user to enter the radius of a circle. Work out the area of
|
|
the circle (π*radius2)."""
|
|
from math import pi
|
|
radio = float(input("Ingresa el radio de la circunferencia: "))
|
|
area = pi*(radio**2)
|
|
print(f"El area de la circunferencia es {round(area, 3)}")
|
|
|
|
def cyl_vol(self):
|
|
"""Ask for the radius and the depth of a cylinder and work out the total
|
|
volume (circle area*depth) rounded to three decimal places."""
|
|
from math import pi
|
|
radio = float(input("Ingresa el radio del cilindro: "))
|
|
largo = float(input("Ingresa el largo del cilindro: "))
|
|
area = pi*(radio**2)
|
|
volumen = round(area*largo, 3)
|
|
print(f"El volumen del cilindro es {volumen}")
|
|
|
|
def friendly_div(self):
|
|
"""Ask the user to enter two numbers. Use whole number division to divide
|
|
the first number by the second and also work out the remainder and
|
|
display the answer in a user-friendly way (e.g. if they enter 7 and 2
|
|
display \"7 divided by 2 is 3 with 1 remaining\")."""
|
|
num_1 = float(input("Ingresa un número: "))
|
|
num_2 = float(input("Ingresa otro número: "))
|
|
res_1 = num_1//num_2
|
|
res_2 = num_1%num_2
|
|
print(f"{num_2} cabe {res_1} veces en {num_1}, y sobran {res_2} ")
|
|
|
|
def circ_trian(self):
|
|
"""Display the following message:
|
|
1) Square
|
|
2) Triangle
|
|
Enter a number:
|
|
If the user enters 1, then it should ask them for the length of one of
|
|
its sides and display the area. If they select 2, it should ask for the
|
|
base and height of the triangle and display the area. If they type in
|
|
anything else, it should give them a suitable error message"""
|
|
print(" 1) Cuadrado\n 2) Triangulo\n")
|
|
choice = input(" Ingresa un número: ")
|
|
match choice:
|
|
case '1':
|
|
side = int(input("Ingresa el largo del cuadrado: "))
|
|
print(f"El area del cuadrado es {side*side}")
|
|
case '2':
|
|
base = int(input("Ingresa la base del triagulo: "))
|
|
altura = int(input("Ingresa la altura del triagulo: "))
|
|
area = round((base*altura)/2, 3)
|
|
print(f"El area del triangulo rectángulo es {area}")
|
|
case _:
|
|
print("Debes escoger una opción válida")
|