Rhea Rajashekhar P4 Popcorn Hacks 3.5

# Popcorn Hack 1: Check Number
def check_number():
    try:
        num = float(input("Enter a number: "))
        print(f"The number {num} is {'negative' if num < 0 else 'non-negative'}.")
    except ValueError:
        print("Invalid input. Please enter a valid number.")
# Popcorn Hack 2: Check Scores
def check_scores():
    try:
        scores = [float(input(f"Enter the score for subject {i + 1}: ")) for i in range(2)]
        print("The student passed both subjects." if all(score >= 70 for score in scores) else "The student did not pass both subjects.")
    except ValueError:
        print("Invalid input. Please enter valid scores.")
# Popcorn Hack 3: Check Vowel
def check_vowel():
    char = input("Enter a character: ").lower()
    print(f"The character '{char}' is {'a vowel' if len(char) == 1 and char in 'aeiou' else 'not a vowel or not valid input'}.")

# Homework 1: Truth Table
cuisine_data = [
    {"Cuisine": "Italian", "Common Food Form": "Pizza", "Country of Origin": "Italy"},
    {"Cuisine": "Chinese", "Common Food Form": "Noodles", "Country of Origin": "China"},
    {"Cuisine": "Mexican", "Common Food Form": "Tacos", "Country of Origin": "Mexico"},
    {"Cuisine": "Indian", "Common Food Form": "Curry", "Country of Origin": "India"},
    {"Cuisine": "Japanese", "Common Food Form": "Sushi", "Country of Origin": "Japan"},
    {"Cuisine": "American", "Common Food Form": "Burger", "Country of Origin": "United States"},
]

# Print header and data
print(f"{'Cuisine':<15} {'Common Food Form':<20} {'Country of Origin':<20}")
print("="*55)
for row in cuisine_data:
    print(f"{row['Cuisine']:<15} {row['Common Food Form']:<20} {row['Country of Origin']:<20}")
# Homework 2: Game Using De Morgan’s Law
def play_game():
    print("Welcome to the High School Program Game!")
    in_ninth = input("Are you in 9th grade? (yes/no): ").lower() == "yes"
    in_tenth = input("Are you in 10th grade? (yes/no): ").lower() == "yes"
    in_eleventh = input("Are you in 11th grade? (yes/no): ").lower() == "yes"
    in_twelfth = input("Are you in 12th grade? (yes/no): ").lower() == "yes"

    if not (in_ninth or in_tenth) and (in_eleventh or in_twelfth):
        print("Congratulations! You win! You're in 11th or 12th grade.")
    else:
        print("Sorry, you do not qualify.")
%% js 
// JS Popcorn Hack 1: Outfit suggestion based on weather
function suggestOutfit() {
    let temperature = parseFloat(prompt("Enter the temperature (in °C):"));
    if (isNaN(temperature)) return alert("Please enter a valid number for the temperature.");
    
    const outfits = [
        { maxTemp: 40, outfit: "Wear a heavy winter coat, scarf, gloves, and boots." },
        { maxTemp: 60, outfit: "Wear a jacket, sweater, and long pants." },
        { maxTemp: 75, outfit: "Wear a light jacket or a sweater, with jeans or casual pants." },
        { maxTemp: 85, outfit: "Wear a t-shirt, shorts, and comfortable shoes." },
        { outfit: "Wear light clothing like tank tops, shorts, and flip-flops." }
    ];
    const suggestion = outfits.find(o => o.maxTemp === undefined || temperature <= o.maxTemp);
    alert(suggestion.outfit);
}
%% js 
// JS Popcorn Hack 2: Which number is bigger?
function sortNumbersAndFindLargest(numbers) {
    const largest = Math.max(...numbers);
    const sortedNumbers = numbers.slice().sort((a, b) => a - b);
    console.log("Sorted Numbers (Least to Greatest):", sortedNumbers);
    console.log("Largest Number:", largest);
}
%% js 
// JS Popcorn Hack 3: Even or Odd?
function checkEvenOrOdd() {
    let number = parseInt(prompt("Enter a number:"));
    if (isNaN(number)) return alert("Please enter a valid number.");
    alert(number % 2 === 0 ? `${number} is an even number.` : `${number} is an odd number.`);
}