# RETO 3.2 num=int(input("Dame 5 numeros")) con=0 total=0 while con!=4: con+=1 Num=int(input("Dame 5 numeros")) num+=Num if num<10: print("La suma en total es menor de 10:",num) elif num==10: print("La suma en total es 10") else: print("La suma en total es mayor de 10:",num)
La suma en total es 10
# RETO 3.1 Num=int(input("Dime un numero")) con=0 while con <= Num: print(con) con+=1
line 2, in <module> Num=int(input("Dime un numero")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
# RETO 2.5 km=int(input("¿Cuantos kilometros recorre?")) t=int(input("¿En cuento tiempo, en horas, lo recorre?")) Vel=km/t #Aqui averiguare los km/h if Vel<=60 and Vel >= 40: print("Felicidades, ha pasado la prueba") else: print("Lo siento, no has pasado la prueba")
Lo siento, no has pasado la prueba
# RETO 2.4 Num=int(input("Insertar numero")) if Num%2==0: if Num<5: print("Tu numero par es menor que 5") else: print("Tu numero par es mayor que 5") else: if Num<10: print("Tu numero impar es menor que 10") else: print("Tu numero impar es mayor que 10")
line 2, in <module> Num=int(input("Insertar numero")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
# RETO 2.3 P=input("¿Tu pizza sera vegana? si/no").lower() if P=="si": Pv=input("Ingredientes de la pizza vegetariana: Pimiento, tofu.¿De que lo quieres?").lower() if Pv=="pimineto": print("¡Encargando una pizza vegana de pimineto señor/a!") elif Pv=="tofu": print("¡Encargando una pizza vegana de tofu señor/a!") else: print("Porfavor, especifique de cual de las dos opciones quiere la pizza") elif P=="no": Pn=input("Ingredientes de la pizza no vegetariana: Peperoni, jamon, salmon. ¿De que lo quieres?").lower() if Pn=="peperoni": print("¡Encargando una pizza de peperoni señor/a!") elif Pn=="jamon": print("¡Encargando una pizza de jamon señor/a!") elif Pn=="salmon": print("¡Encargando una pizza de salmon señor/a!") else: print("Porfavor, especifique de cual de las tres opciones quiere la pizza") else: print("Vuelve a intentarlo. ¿Si o No?")
# RETO2.2 num1=int(input("insertar primer número")) num2=int(input("insertar segundo número")) Letra=input("¿Qué operacion vas a hacer:Sumar(s),Restar(r), Multiplicar(m) o Dividir(d)?").lower() if Letra == "s": resultado= num1+num2 print("Tu suma a resultado en",resultado) elif Letra == "r": resultado= num1-num2 print("Tu suma a resultado en",resultado) elif Letra == "m": resultado= num1*num2 print("Tu suma a resultado en",resultado) elif Letra == "d": resultado= num1/num2 print("Tu suma a resultado en",resultado) else: print("ERROR")
# RETO 2.1 num1=int( input("Primer número")) num2=int( input("Segundo número")) if num1 == num2: print("Tus dos números son iguales") else: print("Tus numeros no son iguales")
# RETO1.4 Num1= float (input("Insertar numero")) Num2= float (input("Insertar numero")) Sum= Num1+Num2 Rest= Num1-Num2 Div= Num1/Num2 Mult= Num1*Num2 print("La suma entre",Num1,"y",Num2,"es",Sum,) print("La resta entre",Num1,"y",Num2,"es",Rest,) print("La división entre",Num1,"y",Num2,"es",Div,) print("La multiplicación entre",Num1,"y",Num2,"es",Mult,)
La suma entre 2.0 y 3.0 es 5.0 La resta entre 2.0 y 3.0 es -1.0 La división entre 2.0 y 3.0 es 0.6666666666666666 La multiplicación entre 2.0 y 3.0 es 6.0
# RETO1.3 X='Ana' Y=15 Z='Juan' W=15 print("Hola mi nombre es",X,"y mi edad es",Y,".Tu eres",Z,"y tu edad es",W)
Hola mi nombre es Ana y mi edad es 15 .Tu eres Juan y tu edad es 15
# RETO1.2 nombre="jacob" Edad=15 print("Hola, soy",nombre,"y tengo",Edad,"años")
Hola, soy jacob y tengo 15 años 1530 45
# RETO1.1 print("Hola mundo")
In Python, `float` is a data type used to represent floating-point numbers – numbers with decimal points. You use it in a few ways: **1. To declare a variable as a float:** You don't directly *declare* the type in Python like you might in some other languages (e.g., `float Num1;` in C++). Python infers the type. However, you can assign a floating-point value to a variable to make it a float: ```python Num1 = 3.14 # Num1 is now a float Num2 = 10.0 # Num2 is also a float Num3 = float(5) # Num3 is a float (casting integer 5 to a float) ``` **2. To convert other data types to floats:** Python's `float()` function converts other numeric data types (like integers and strings representing numbers) into floats: ```python integer_value = 10 float_value = float(integer_value) # float_value will be 10.0 string_value = "3.14159" float_value = float(string_value) # float_value will be 3.14159 #Attempting to convert a non-numeric string will raise a ValueError string_value = "hello" #float_value = float(string_value) # This will cause a ValueError ``` **3. In arithmetic operations:** Floats are used naturally in arithmetic operations where decimal precision is needed: ```python result = 10.5 + 5.2 print(result) # Output: 15.7 result = 10 / 3 # Even with integer division, the result is a float in Python 3 print(result) # Output: 3.3333333333333335 ``` **Example incorporating `float` into RETO1.4:** The provided `RETO1.4` code snippet is incomplete:
# RETO1.4 Num1= Num2= float
line 2 Num1= ^ SyntaxError: invalid syntax
To make it functional, you need to assign values:
# RETO1.4 Num1 = 10.5 Num2 = 5.2 sum_of_numbers = Num1 + Num2 #addition of floats print(f"The sum is: {sum_of_numbers}") #formatted string to display the sum # Or alternatively: Num3 = float(10) #Convert an integer to a float Num4 = float("7.7") #Convert a string to a float print(Num3 + Num4)
The sum is: 15.7 17.7
Remember that attempting to use `float` without providing a numeric value (integer or string representing a number) will lead to an error. You must give it something to convert *to* a float.