#1
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
Celsius_list = []
choice = "Yes"
while choice == "Yes":
Celsius_list.append(float(input("Celsius: ")))
choice = input("Do you want to continue? Yes or No: ").capitalize()
if choice == "No":
break
a=1
Fahrenheit_List = []
for celsius in Celsius_list:
fahrenheit = celsius_to_fahrenheit(celsius)
Fahrenheit_List.append(fahrenheit)
print(f"{a}. {celsius} Celsius is {fahrenheit} Fahrenheit")
a += 1
#2
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
Fahrenheit_list = []
choice = "Yes"
while choice == "Yes":
Fahrenheit_list.append(float(input("Fahrenheit: ")))
choice = input("Do you want to continue? Yes or No: ").capitalize()
if choice == "No":
break
a=1
Celsius_List = []
for fahrenheit in Fahrenheit_list:
celsius = fahrenheit_to_celsius(fahrenheit)
Celsius_List.append(celsius)
print(f"{a}. {fahrenheit} Fahrenheit is {celsius} Celsius")
a += 1
#3
num1 = int(input("Enter num 1: "))
num2 = int(input("Enter num 2: "))
fibonacci = []
for i in range(15):
print(num1, end=" ")
fibonacci.append(num1)
value = num1
num1 = num2
num2 += value
print(f"\n9th term: {fibonacci[8]}")
#4
num1 = int(input("Enter num 1: "))
num2 = int(input("Enter num 2: "))
fibonacci = []
for i in range(15):
print(num1, end=" ")
fibonacci.append(num1)
value = num1
num1 = num2
num2 += value
print(f"\n9th term: {fibonacci[13]}")
#5
names = []
index = 0
while True:
name = input("Enter a name: ")
if name == "no":
break
names.append(name)
for name in names:
print(f"Index {index}: {name}")
index += 1
#6
numbers = []
index = 0
while True:
num = input("Enter a number: ")
if num == "no":
break
numbers.append(int(num))
for number in numbers:
print(f"Index {index}: {number}")
index += 1
#7
list1 = input("Enter numbers for list 1: ").split()
list2 = input("Enter numbers for list 2: ").split()
list1 = [int(num) for num in list1]
list2 = [int(num) for num in list2]
merged_list = []
for num in list1 + list2:
if num not in merged_list:
merged_list.append(num)
merged_list.sort()
print(merged_list)
#8
list1 = input("Enter numbers for list 1: ").split()
list2 = input("Enter numbers for list 2: ").split()
list1 = [int(num) for num in list1]
list2 = [int(num) for num in list2]
common_elements = []
for num in list1:
if num in list2 and num not in common_elements:
common_elements.append(num)
common_elements.sort()
print(common_elements)
#9
odd_Bank = []
even_Bank = []
choice = "Yes"
while choice == "Yes":
odd = int(input("Enter odd number/s: "))
even = int(input("Enter even number/s: "))
if odd % 2 != 0:
odd_Bank.append(odd)
if even % 2 == 0:
even_Bank.append(even)
choice = input("Continue Yes or No: ").capitalize()
merged = odd_Bank + even_Bank
odd_num = [num for num in merged if num % 2 != 0]
print(f"Merged List: {merged}")
print(f"Odd Numbers: {odd_num}")
#10
odd_Bank = []
even_Bank = []
choice = "Yes"
while choice == "Yes":
odd = int(input("Enter odd number/s: "))
even = int(input("Enter even number/s: "))
if odd % 2 != 0:
odd_Bank.append(odd)
if even % 2 == 0:
even_Bank.append(even)
choice = input("Continue Yes or No: ").capitalize()
merged = odd_Bank + even_Bank
even_num = [num for num in merged if num % 2 == 0]
print(f"Merged List: {merged}")
print(f"Odd Numbers: {even_num}")
#bautista
odd_Bank = []
even_Bank = []
choice = "Yes"
while choice == "Yes":
odd = int(input("Enter odd number/s: "))
even = int(input("Enter even number/s: "))
if odd % 2 != 0:
odd_Bank.append(odd)
if even % 2 == 0:
even_Bank.append(even)
choice = input("Continue (Yes or No): ").capitalize()
merged = odd_Bank + even_Bank
print(f"Merged: {merged}")
print(f"Odd numbers: {odd_Bank}")
print(f"Even numbers: {even_Bank}")
#jaime
odd_Bank = []
even_Bank = []
choice = "Yes"
while choice == "Yes":
odd_Bank.append(int(input("Enter odd number/s: ")))
even_Bank.append(int(input("Enter even number/s: ")))
choice = input("Continue Yes OR No: ")
if choice == "No":
break
odd_Bank.extend(even_Bank)
merged = odd_Bank + even_Bank
odd_numbers = [num for num in merged if num % 2 != 0]
even_numbers = [num for num in merged if num % 2 == 0]
print(f"merged: {merged}")
print(f"Odd numbers: {odd_numbers}")
print(f"Even numbers: {even_numbers}")
#list manipulation
def get_list():
numbers = input("Enter numbers: ").split()
return [int(num) for num in numbers]
def display_lists(list1, list2):
print("\nList 1:", list1)
print("List 2:", list2)
def remove_duplicates(lst):
unique_list = []
for num in lst:
if num not in unique_list:
unique_list.append(num)
return unique_list
def main():
print("List 1 :")
list1 = get_list()
print("List 2 :")
list2 = get_list()
combined = []
while True:
print("\nMenu:\n1. Show Lists\n2. Delete Element\n3. Update Element\n4. Combine Lists\n5. Remove
Duplicates\n6. Sort List\n7. Show Final List\n8. Exit")
choice = input("Choose option: ")
if choice == "1":
display_lists(list1, list2)
elif choice == "2":
lst = list1 if input("Delete from List 1 or 2? ") == "1" else list2
num = int(input("Enter number to delete: "))
if num in lst:
lst.remove(num)
print("Deleted successfully.")
else:
print("Number not found.")
elif choice == "3":
lst = list1 if input("Update in List 1 or 2? ") == "1" else list2
old = int(input("Enter old value: "))
new = int(input("Enter new value: "))
if old in lst:
index = lst.index(old)
lst[index] = new
print("Updated successfully.")
else:
print("Number not found.")
elif choice == "4":
combined = list1 + list2
print("\nCombined List:", combined)
elif choice == "5":
combined = remove_duplicates(combined)
print("\nList without duplicates:", combined)
elif choice == "6":
combined.sort()
print("\nSorted List:", combined)
elif choice == "7":
print("\nFinal Sorted List:", combined)
elif choice == "8":
print("Exiting program...")
break
else:
print("Invalid choice, try again.")
if __name__ == "__main__":
main()
day = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
for x, y in enumerate(day):
print(f"{x}. {y}")
print("Chose number of days:")
choice = int(input("Enter current day: "))
ahead = int(input("Enter days ahead: "))
future_day_num = (choice + ahead) % 7
future_day = day[future_day_num]
week_passed = ahead // 7
if week_passed >= 1:
print(f"{future_day}, {week_passed} weeks later.")
else:
print(f"{future_day}")
# Student IDs list
student_ids = [8, 1, 2, 5, 8, 1, 4, 3, 2, 1]
# Count total number of students manually
count_students = 0
for _ in student_ids:
count_students += 1 # Manually count elements
# Get user input
numberStud = int(input("Enter number of students: "))
# Validate input without using len()
if numberStud >= 1:
valid = False
for i in range(count_students):
if numberStud == i + 1:
valid = True
break
if valid:
# Extract the first `numberStud` IDs
nums = []
index = 0
while index < numberStud:
nums.append(student_ids[index])
index += 1
print("Student ID number list:", nums)
# Identify unique and duplicate IDs
unique = []
dup = []
for ele in nums:
found = False
for item in unique:
if item == ele:
found = True
break
if not found:
unique.append(ele)
else:
exists = False
for item in dup:
if item == ele:
exists = True
break
if not exists:
dup.append(ele)
print("Unique IDs:", unique)
print("Duplicate IDs:", dup)
# Count occurrences of duplicate IDs
counts = {}
for num in nums:
duplicate = False
for d in dup:
if num == d:
duplicate = True
break
if duplicate:
if num not in counts:
count = 0
for n in nums:
if n == num:
count += 1
counts[num] = count
# Display duplicate counts
for num in counts:
print(f"Student ID {num} affected: {counts[num]} times")
else:
print(f"Invalid input. Please enter a number between 1 and {count_students}")
else:
print(f"Invalid input. Please enter a number between 1 and {count_students}")
n1 = 3 # Roof height
top_width = 3
bottom_width = 7
# Calculate house dimensions
house_height = (bottom_width + 1) // 2
house_width = bottom_width // 2
# Roof (trapezoid)
for i in range(n1):
spaces = (bottom_width - (top_width + 2 * i)) // 2
if spaces < 0:
break
print(" " * spaces + "*" * (top_width + 2 * i))
# House (rectangle)
for _ in range(house_height):
house_spaces = (bottom_width - house_width) // 2
print(" " * house_spaces + "*" * house_width)
def letter_flip(text):
abc = "abcdefghijklmnopqrstuvwxyz"
ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
flipped_abc = abc[::-1]
flipped_ABC = ABC[::-1]
result = ""
for char in text:
if char in abc:
result += flipped_abc[abc.index(char)]
elif char in ABC:
result += flipped_ABC[ABC.index(char)]
else:
result += char
return result
text = input("Enter text: ")
print("Flipped:", letter_flip(text))
def sum_matrix_excluding_corners(matrix):
row1 = matrix[0] # First row
row2 = matrix[1] # Middle row
row3 = matrix[2] # Last row
# Summing all elements except the four corners
total = (row1[1] +
row2[0] + row2[1] + row2[2] +
row3[1])
return total
# Example usage
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(sum_matrix_excluding_corners(matrix))