Professional Documents
Culture Documents
AN AUTONOMOUS INSTITUTION
Approved by AICTE, New Delhi and Affiliated to Anna University, Chennai
Solutions
2. def sum_even(numbers):
total = 0
for num in numbers:
if num % 2 == 0:
total += num
return total
4.def count_vowels(string):
vowels = "aeiou"
count = 0
for char in string:
if char.lower() in vowels:
count += 1
return count
5. import random
6. def longest_word(words):
longest = ""
for word in words:
if len(word) > len(longest):
longest = word
return longest
7. with open("numbers.txt") as file:
numbers = [int(line.strip()) for line in file]
total = sum(numbers)
print("The sum of the numbers is: " + str(total))