HAsta ahora hemos aprendido a introducir en la computadora dos tipos de numeros:
float: numeros con decimalesint: numeros enteros
Copia el codigo abajo y mira las operaciones adding = 4 + 3
print(adding)
subtraction = 8 - 9
print(subtraction)
multiplication = 4 * 32
print(multiplication)
division = 50 / 5
print(division)
# a number raised to the power of some number
# in this example we raise 5 to the power of 2
squared = 5**2
print(squared)
# remainder of a division
modulo = 15 % 4
print(modulo)
# whole number division
divisor = 15 // 2
print(divisor)
## Arregla este codigo
Borra el codigo que tenemos hasta ahora, copia y pega el siguiente codigo y verifica donde estan los errores, solucionalos
👉 # Solve the following problems with my code
# Your goal is to print the solution of all 3 calculations to the screen.
# multiplication
3.4 * 6.8
# division
2467 / 4673
#raise 10 to the power of 2
# print the remainder when 343 is divided by 4
print("343 // 100")
### Solucion:
# 👉 Solve the following problems with my code
# Your goal is to print the solution of all 3 calculations to the screen.
# multiplication
print(3.4 * 6.8)
# division
print(2467 / 4673)
#raise 10 to the power of 2
print(10**2)
# print the remainder when 343 is divided by 4
print(343 // 100)
## Dividamos la cuenta ¿Te divertiste con todos esos simbolos matematicos?, pongamoslo en buen uso:
Tu y tus amigos fueron a cenar y necesitan dividir la cuenta. Siendo el amigo mas inteligente que eres, usas tu codigo para saber cuanto le toca a cada uno. Recuera que
myBilles un float y probablemente tenga decimales ynumberOfPeoplees un int porque no vas a cenar coin dos personas y media.
Copia y mira que pasa:
myBill = float(input("What was the bill?: "))
numberOfPeople = int(input("How many people?: "))
answer = myBill / numberOfPeople
print("You all owe", answer)
¿Recibiste un numero con muchos decimales?
Puedes tomar tu resouesta y usar round. Round tiene dos componentes:
Ahora añade esta porcion de codigo a la respuesta y mira que sucede:
myBill = float(input("What was the bill?: "))
numberOfPeople = int(input("How many people?: "))
answer = round((myBill / numberOfPeople), 2)
print("You all owe", answer)
puede ser de esta manera, o de esta:
myBill = float(input("What was the bill?: "))
numberOfPeople = int(input("How many people?: "))
answer = myBill / numberOfPeople
answer = round(answer, 2)
print("You all owe", answer)
Extiende tu calculadora de cuenta: Añade una funcion que sume la propina total antes de calcular la parte de cada quien
La solucion la tendras en main.py