Python Mid
Python Mid
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
Celsius_list = []
choice = "Yes"
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"
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
#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
#5
names = []
index = 0
while True:
name = input("Enter a name: ")
if name == "no":
break
names.append(name)
#6
numbers = []
index = 0
while True:
num = input("Enter a number: ")
if num == "no":
break
numbers.append(int(num))
#7
list1 = input("Enter numbers for list 1: ").split()
list2 = input("Enter numbers for list 2: ").split()
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()
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)
#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)
#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)
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
#list manipulation
def get_list():
numbers = input("Enter numbers: ").split()
return [int(num) for num in numbers]
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()
for x, y in enumerate(day):
print(f"{x}. {y}")
week_passed = ahead // 7
if week_passed >= 1:
print(f"{future_day}, {week_passed} weeks later.")
else:
print(f"{future_day}")
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)
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)
n1 = 3 # Roof height
top_width = 3
bottom_width = 7
# 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
def sum_matrix_excluding_corners(matrix):
row1 = matrix[0] # First row
row2 = matrix[1] # Middle row
row3 = matrix[2] # Last row
return total
# Example usage
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(sum_matrix_excluding_corners(matrix))