Open Jowan3 opened 1 week ago
Python hacks:
Hack 1:
my_var = 42 print(f"Step 1 - Value: {my_var}, Type: {type(my_var)}")
my_var = "Hello, World!" print(f"Step 2 - Value: {my_var}, Type: {type(my_var)}")
my_var = 3.14 print(f"Step 3 - Value: {my_var}, Type: {type(my_var)}")
my_var = True print(f"Step 4 - Value: {my_var}, Type: {type(my_var)}")
Hack 2 (Variable Swapping (without a third variable)
Step 1: a = 5 b = 10
Step 2: a, b = b, a #
Step 3: print("a =", a) print("b =", b)
Hack 3 Variables in Memory
Step 1: var1 = 100 var2 = 100
Step 2: same_memory = id(var1) == id(var2)
Step 3: print(f"var1 and var2 point to the same memory location: {same_memory}") print(f"Memory address of var1: {id(var1)}") print(f"Memory address of var2: {id(var2)}")
JavaScript hacks
Hack 1: Naming Variables for User Profile
// Creating variables for user profile let fullName = "Jowan Elzein"; let age = 22; // You can adjust the age if you'd like let email = "jowan@example.com"; let accountBalance = 1500;
// Displaying the information
console.log(${fullName}, aged ${age}, can be contacted at ${email} and has a balance of $${accountBalance} in his account.
);
Hack 2: Store Product Inventory
// Variables for first product let productName1 = "Laptop"; let productPrice1 = 1200; let productStock1 = 10;
// Variables for second product let productName2 = "Smartphone"; let productPrice2 = 800; let productStock2 = 15;
// Output messages describing stock and prices
console.log(The store has ${productStock1} units of ${productName1} priced at $${productPrice1} each.
);
console.log(The store has ${productStock2} units of ${productName2} priced at $${productPrice2} each.
);
Hack 3: Total Price After Tax Calculation
// Variables for item price, quantity, tax rate let itemPrice = 20; let quantity = 3; let taxRate = 0.10;
// Calculating total price after tax let totalPriceAfterTax = itemPrice quantity (1 + taxRate);
// Displaying the total price
console.log(The total price for ${quantity} items each priced at $${itemPrice} with a tax rate of ${taxRate * 100}% is $${totalPriceAfterTax.toFixed(2)}.
);
Popcorn Hack 1: Python (pascal Case Variable)
MyFirstVariable = "This is a PascalCase variable" print(MyFirstVariable)
Popcorn hack 2: Camel Case Variable
mySecondVariable = 42 print(mySecondVariable)
Popcorn Hack 3: Create Differnt Varibles (string, intergers, Float)
String variable
favoriteGame = "The Legend of Zelda"
Float variable
piApprox = 3.14
Integer variable
levelInGame = 5
print(favoriteGame) print(piApprox) print(levelInGame)