Ellioty15 / Elliot_2025

Apache License 2.0
0 stars 0 forks source link

3.2 Hacks #8

Open Ellioty15 opened 1 month ago

Ellioty15 commented 1 month ago

Popcorn Hack 3.2.1

def add_two_numbers(num1, num2): """Function to add two integers.""" return num1 + num2

//Get user input try: //Prompt the user for two integers first_number = int(input("Enter the first integer: ")) second_number = int(input("Enter the second integer: "))

//Call the function to add the numbers
result = add_two_numbers(first_number, second_number)

//Print the result
print(f"The sum of {first_number} and {second_number} is: {result}")

except ValueError: print("Please enter valid integers.")

#Popcorn Hack 3.2.2 //Creating a dictionary person = { "name": "Alice", "age": 25, "is_student": False }

//Update an item in the dictionary person["age"] = 26 # Updating Alice's age

//Adding a new item (a new person entry in this case) person["David"] = { "name": "David",
"age": 22, "is_student": True }

//Printing the updated dictionary print(person)

# Starting dictionary person = { "name": "Alice", "age": 30 }

//i. Update the age to 31 person["age"] = 31

//ii. Print the updated dictionary print("Updated Person Dictionary:", person)

Popcorn Hack function isNull(val) { return val === null ? "No value" : "Value exists"; }

// Test the function console.log(isNull(null)); // Output: No value console.log(isNull(10)); // Output: Value exists