Rhea Rajashekhar P4 Popcorn Hacks 3.8
# Popcorn Hack 1
count = 0
# Start the while loop
while count < 5:
print("hello")
count += 1 # Increment the counter
# Popcorn Hack 2
outer_count = 0
# Start the outer loop to repeat the whole sequence 4 times
while outer_count < 4:
# Print first name once
first_name_count = 0
while first_name_count < 1:
print("Rhea")
first_name_count += 1
# Print middle name as a space twice
middle_name_count = 0
while middle_name_count < 2:
print(" ")
middle_name_count += 1
# Print last name three times
last_name_count = 0
while last_name_count < 3:
print("Rajashekhar")
last_name_count += 1
# Increment the outer loop counter
outer_count += 1
# Popcorn Hack 3
for letter in "Rhea":
print(letter)
# Popcorn Hack 4
student_grades = {
"Student 1": "A",
"Student 2": "B+",
"Student 3": "A-",
"Student 4": "B",
"Student 5": "A+"
}
# Loop through each key-value pair
for student, grade in student_grades.items():
print(f"{student} received a grade of {grade}. Great job!")
# python homework 1: password check
def is_valid_password(password):
has_upper = any(c.isupper() for c in password)
has_lower = any(c.islower() for c in password)
has_number = any(c.isdigit() for c in password)
has_special = any(c in '!@#$%^&*(),.?":{}|<>' for c in password)
no_spaces = ' ' not in password
long_enough = len(password) >= 10
no_consecutive_chars = not any(password[i] == password[i+1] == password[i+2] == password[i+3] for i in range(len(password)-3))
return has_upper and has_lower and has_number and has_special and no_spaces and long_enough and no_consecutive_chars
def create_password():
password = input("Enter your password: ")
if is_valid_password(password):
print("Your password is valid!")
else:
print("Invalid password. Follow these rules:")
print("1. At least 10 characters long.")
print("2. Contains uppercase and lowercase letters.")
print("3. Has at least one number.")
print("4. No spaces.")
print("5. Includes at least 1 special character.")
print("6. No more than 3 identical consecutive characters.")
create_password()
# hack 2
user_name = input("Rhea: ")
# Iterate through each letter in the name
for letter in user_name:
print(letter)
# hack 3
fruits = ["Apple", "Banana", "Orange", "Mango", "Grapes", "Pineapple", "Strawberry"]
# Loop through the list and print each fruit
for fruit in fruits:
print(fruit)
%% js
// Popcorn Hack 1
let count = 0;
// Start the while loop
while (count < 5) {
console.log("hello");
count++; // Increment the counter
}
%% js
// Popcorn Hack 2
for (let letter of "Rhea") {
console.log(letter);
}
%% js
// Popcorn Hack 3
let correctPassword = "javascript";
// Variable to control the loop
let isPasswordCorrect = false;
// Simulate a password checking loop
while (!isPasswordCorrect) {
let userInput = prompt("Please enter the password:");
if (userInput === correctPassword) {
console.log("The password is correct!");
isPasswordCorrect = true; // Exit the loop
} else {
console.log("Incorrect password, please try again.");
}
}
%% js
// Popcorn Hack 4
let studentGrades = {
"Student 1": "A",
"Student 2": "B+",
"Student 3": "A-",
"Student 4": "B",
"Student 5": "A+"
};
// Loop through each key-value pair using for...in loop
for (let student in studentGrades) {
console.log(`${student} received a grade of ${studentGrades[student]}. Great job!`);
}