Alerta de temperatura

Muestra una alerta si la temperatura (°C) es alta. (Ejemplo: alerta si ≥ 30°C)

← Volver a Artículos



¿Cómo generar una alerta según la temperatura?

Este ejercicio solicita al usuario ingresar un valor de temperatura en grados Celsius y evalúa si es mayor o igual a 30. En ese caso, se muestra una alerta de temperatura alta; de lo contrario, se indica que la temperatura es normal. Es útil para practicar condiciones aplicadas a escenarios reales.



Solución en PSeInt

Proceso AlertaTemperatura
    Definir temp Como Real;

    Escribir "Ingrese la temperatura (°C): ";
    Leer temp;

    Si temp >= 30 Entonces
        Escribir "¡Alerta! Temperatura alta"
    FinSi
FinProceso


Solución en Python

temp = float(input("Ingrese la temperatura (°C): "))
if temp >= 30:
    print("¡Alerta! Temperatura alta")


Solución en Python (Tkinter)

import tkinter as tk
from tkinter import messagebox

def verificar():
    try:
        temp = float(entry.get())
        if temp >= 30:
            messagebox.showwarning("Alerta", "¡Alerta! Temperatura alta")
    except ValueError:
        messagebox.showerror("Error", "Ingrese un número válido")

root = tk.Tk(); root.title("Alerta de temperatura")
tk.Label(root, text="Temperatura (°C):").pack()
entry = tk.Entry(root); entry.pack()
tk.Button(root, text="Verificar", command=verificar).pack()
root.mainloop()


Solución en JavaScript

let temp = parseFloat(prompt("Ingrese la temperatura (°C):"));
if (!isNaN(temp)) {
    if (temp >= 30) alert("¡Alerta! Temperatura alta");
    else alert("Temperatura normal");
}


Solución en C++ (Dev C++)

#include <iostream>
using namespace std;
int main() {
    double temp;
    cout << "Ingrese la temperatura (°C): ";
    cin >> temp;
    if (temp >= 30) cout << "¡Alerta! Temperatura alta" << endl;
    return 0;
}


Solución en C#

using System;
class Program {
    static void Main() {
        Console.Write("Ingrese la temperatura (°C): ");
        double temp = double.Parse(Console.ReadLine());
        if (temp >= 30) Console.WriteLine("¡Alerta! Temperatura alta");
    }
}


Solución en Java (NetBeans)

import java.util.Scanner;
public class AlertaTemperatura {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Ingrese la temperatura (°C): ");
        double temp = sc.nextDouble();
        if (temp >= 30) System.out.println("¡Alerta! Temperatura alta");
    }
}


Solución en Excel

=SI(A1>=30;"Alerta - Temperatura alta";"Temperatura normal")

Publicado por: ObiWan
Fecha: 10/09/2025