R

@Rueda

Con parámetros y con retorno

Python
9 months ago
def promedio(n1, n2, n3): return (n1 + n2 + n3) / 3 prom = promedio(4.5, 3.8, 5.0) print("Promedio:", prom)

Sin parámetros y con retorno

Python
9 months ago
def es_negativo(): num = int(input("Ingresa un número: ")) return num < 0 if es_negativo(): print("El número es negativo.") else: print("El número no es negativo.")

Con parámetros y sin retorno

Python
9 months ago
def saludar(nombre): print("Hola", nombre, "¡Bienvenido!") # Llamada a la función con un parámetro saludar("Alejandro")

sin parametros sin retorno

Python
9 months ago
def mayor_de_edad(): edad = int(input("Ingrese su edad: ")) if edad >= 18: print("Es mayor de edad.") else: print("Es menor de edad.") mayor_de_edad()

prueba

Python
1 year ago
numero= int(input(" El ultimo numero de la placa de su vehiculo: ")) if numero == 0 or 1: print(" Tiene pico y placa el lunes ") if numero >=2 and 3: print ("Tiene pico y placa el martes")

Cumpleaños

Python
1 year ago
try: dia_hoy = int(input("Día actual del año (1-365): ")) dia_cumple = int(input("Día de tu cumpleaños en el año (1-365): ")) if dia_cumple >= dia_hoy: dias_faltantes = dia_cumple - dia_hoy else: dias_faltantes = (365 - dia_hoy) + dia_cumple print(f"Faltan {dias_faltantes} días para tu cumpleaños. ")

peso

Python
1 year ago
altura = input(float()) print("introduce tu altura: " + dato) peso = input (int()) print("introduce tu peso: " + peso) ) peso = alt if 60 > peso < 90 :

Pico y placa

Python
1 year ago
placa = input("Ingresa la placa del carro: ") ultimo_digito = placa[-1] if not ultimo_digito.isdigit(): print(" Error: La placa debe terminar en un número.") else: ultimo_digito = int(ultimo_digito)

Calculadora (Datos incluidos)

Python
1 year ago
def calculadora(a, b, operacion): if operacion == 'suma': return a + b elif operacion == 'resta': return a - b elif operacion == 'multiplicacion': return a * b elif operacion == 'division': if b != 0: return a / b

13. Cálculo de Sumas Acumulativas

C++
1 year ago
#include <iostream> int main() { int N; std::cout << "Ingrese el valor de N: "; std::cin >> N; if (N <= 0) { std::cout << "El valor de N debe ser un número entero positivo." << std::endl; return 1;

12. Serie de Potencias:

C++
1 year ago
#include <iostream> #include <cmath> int main() { int N; std::cout << "Ingrese el valor de N: "; std::cin >> N; if (N <= 0) { std::cout << "El valor de N debe ser un número entero positivo." << std::endl;

11. Números Primos hasta N:

C++
1 year ago
#include <iostream> #include <cmath> bool esPrimo(int numero) { if (numero <= 1) return false; if (numero <= 3) return true; if (numero % 2 == 0 || numero % 3 == 0) return false; for (int i = 5; i * i <= numero; i += 6) { if (numero % i == 0 || numero % (i + 2) == 0) return false; }

10. Suma de los Primeros N Números:

C++
1 year ago
#include <iostream> int main() { int N; std::cout << "Ingrese el valor de N: "; std::cin >> N; if (N <= 0) { std::cout << "El valor de N debe ser un número entero positivo." << std::endl;

9. Tabla de Multiplicar

C++
1 year ago
#include <iostream> using namespace std; int main() { int N; cout << "Ingresa un número entero para mostrar su tabla de multiplicar: "; cin >> N; cout << "Tabla de multiplicar del " << N << ":" << endl;

8. Raíz Cuadrada Aproximada:

C++
1 year ago
#include <iostream> #include <cmath> using namespace std; int main() { double numero, epsilon, bajo, alto, medio; cout << "Ingresa un número positivo para calcular su raíz cuadrada: "; cin >> numero;

7. Conteo de Números Primos:

C++
1 year ago
#include <iostream> using namespace std; bool esPrimo(int num) { if (num <= 1) return false; if (num <= 3) return true; if (num % 2 == 0 || num % 3 == 0) return false;

6. Conteo de Números Divisibles por 3 y 5:

C++
1 year ago
#include <iostream> using namespace std; int main() { int N; cout << "Ingresa un número entero positivo N: "; cin >> N; if (N <= 0) {

5. Suma de Dígitos:

C++
1 year ago
#include <iostream> using namespace std; int main() { int numero; cout << "Ingresa un número entero positivo: "; cin >> numero; if (numero <= 0) {

4. Contador de Dígitos:

C++
1 year ago
#include <iostream> using namespace std; int main() { int numero; cout << "Ingresa un número entero: "; cin >> numero; if (numero == 0) {

3. Cálculo del Máximo Común Divisor (MCD):

C++
1 year ago
#include <iostream> using namespace std; int main() { int a, b; cout << "Ingresa el primer número entero positivo: "; cin >> a; cout << "Ingresa el segundo número entero positivo: "; cin >> b;