Free FOUNDATIONS-OF-PROGRAMMING-PYTHON Practice Test Questions and Answers (2026)
SIMULATION Fix the indexing error in this function that should return the last character of a string. def get_last_character(text): return text[len(text)]
SIMULATION Write a complete function password_strength(password) that returns "Strong" if the password is at least 8 characters long and contains both letters and numbers, "Weak" otherwise. For example, password_strength("abc123def") should return "Strong". def password_strength(password): # TODO: Return "Strong" or "Weak" based on password criteria if len(password) < 8: return "Weak" has_letter = False has_number = False for char in password: if char.isalpha(): has_letter = True elif char.isdigit(): has_number = True # TODO: Add your return logic here based on has_letter and has_number pass
SIMULATION Fix the indentation error in this function that should return a greeting message. def greet(name): return "Hello " + name
SIMULATION Complete the function calculate_tip(bill, tip_percent) that calculates and returns the tip amount based on the bill and tip percentage. For example, calculate_tip(50, 20) should return 10.0. def calculate_tip(bill, tip_percent): # TODO: Calculate and return the tip amount pass
SIMULATION Complete the function is_positive(number) that returns True if the number is greater than 0, and False otherwise. def is_positive(number): # TODO: Return True if number > 0, False otherwise pass