- Cambiando Números
- Exponenciales
- El Módulo
- La Concatenación
- El Más Igual
- Strings Multilinea
- Ejercicios
Funcionalidad #8 - Cambiando Números
ice_cream_price = 1.50 number_of_ice_creams = 4 # prints "6.0" print(ice_cream_price * number_of_ice_creams) # prints "1.5" print(ice_cream_price) #prints #4 print(number_of_ice_creams) # Updating the price ice_cream_price = 2 # prints "8.0" print(ice_cream_price * number_of_ice_creams) # prints "2" print(ice_cream_price) #prints #4 print(number_of_ice_creams)
Funcionalidad #9 - Exponenciales
# 2 to the 10th power, or 1.24 print(2 ** 10) # 8 squared, or 64 print(8 ** 2) # 9 * 9 * 9, 9 cubed, or 729 print(9 ** 3) # We can even perform fractional exponents, 4 to the half power, or 2 print(4 ** 0.5)
Funcionalidad #10 - El Módulo
# prints 4 because 29/5 is 5 with a remainder of 4 print(29 % 5) # prints 2 because 32/3 is 10 with a remainder of 2 print(32 % 3) # Modulo by 2 returns 0 for even numbers and 1 for odd numbers # print 0 print(44 % 2)
Funcionalidad #11 - La Concatenación
my_birthday = "I am " age = 19 my_birthday_two = " years old" # Concatenating an integer with strings is possible if we turn the integer into a string first full_string = my_birthday + str(age) + my_birthday_two # prints "I am 19 years old"
Funcionalidad #12 - El Más Igual
# we have a variable with a number saved number_km_runned = 10 # we need to update with another 2 kms today number_km_runned += 2 # when we print, the new value is the old value plus the number after plus-euqlas print(number_km_runned) #Prints 12
Funcionalidad #13 - Strings Multilinea
lorem_ipsum = """ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. """
Ejercicio Final
string1 = "The wind, " string2 = "which had hitherto carried us along with amazing rapidity, " string3 = "sank at sunset to a light breeze; " string4 = "the soft air just ruffled the water and " string5 = "caused a pleasant motion among the trees as we approached the shore, " string6 = "from which it wafted the most delightful scent of flowers and hay."
10- Estamos haciendo compras en línea y encontramos un par de zapatillas nuevas. Justo antes de que nos vayamos, encontramos un bonito suéter y algunos libros que también queremos comprar! Utilice el operador += para actualizar el precio_total e incluir los precios de nice_sweater y fun_books.
Solucion Ejercicio
quilt_width = 8 quilt_length = 12 print(quilt_width * quilt_length) quilt_length = 8 print(quilt_width * quilt_length)
total_price = 0 new_sneakers = 50.00 total_price += new_sneakers nice_sweater = 39.00 fun_books = 20.00 # Update total_price here: total_price += nice_sweater total_price += fun_books print("The total price is", total_price)
PD: Si quieres profundizar y estudiar python en detalle, te recomendamos este excelente curso de avanzado a intermedio en Python.