Python Programs
Python Programs
def replace_vowels(string):
vowels = "aeiouAEIOU"
new_string = ""
for char in string:
if char in vowels:
new_string += "&"
else:
new_string += char
return new_string
input_string = input("Enter a string: ") # Get string input from the user
modified_string = replace_vowels(input_string)
print("Modified string:", modified_string)
def is_palindrome(string):
reversed_string = string[::-1]
if string == reversed_string:
return True
else:
return False
print("After swapping:")
print("First number:", num1)
print("Second number:", num2)
def calculator():
while True:
print("\nCalculator Menu:")
print("1. Addition (+)")
print("2. Subtraction (-)")
print("3. Multiplication (*)")
print("4. Division (/)")
print("5. Exit")
if choice == '5':
print("Exiting calculator. Goodbye!")
break
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
result = num1 + num2
print("Result:", result)
elif choice == '2':
result = num1 - num2
print("Result:", result)
elif choice == '3':
result = num1 * num2
print("Result:", result)
elif choice == '4':
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
result = num1 / num2
print("Result:", result)
else:
print("Invalid choice. Please enter a number between 1 and 5.")
except ValueError:
print("Invalid input. Please enter numbers only.")
if __name__ == "__main__":
calculator()
if string == string[::-1]:
print(string, "is a palindrome")
else:
print(string, "is not a palindrome")
list2 = []
for item in list1:
if item not in list2:
list2.append(item)
print(list2)
list3 = list(set(list1))
print(list3)
if position != -1:
print(f"The number {num_to_check} is present at position
{position}.")
else:
print(f"The number {num_to_check} is not present in the list.")
sum_of_values = 0
for value in my_dict.values():
sum_of_values += value
print(sum_of_values)