You are on page 1of 3

SNS COLLEGE OF ENGINEERING

Kurumbapalayam (Po), Coimbatore – 641 107

AN AUTONOMOUS INSTITUTION
Approved by AICTE, New Delhi and Affiliated to Anna University, Chennai

Solutions

1. name = input("What is your name? ")


age = input("How old are you? ")
print("Hello " + name + ", you are " + age + " years old!")

2. def sum_even(numbers):
total = 0
for num in numbers:
if num % 2 == 0:
total += num
return total

3.celsius = float(input("Enter a temperature in Celsius: "))


fahrenheit = (celsius * 1.8) + 32
print("The temperature in Fahrenheit is: " + str(fahrenheit))

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

number = random.randint(1, 100)


guess = int(input("Guess a number between 1 and 100: "))

while guess != number:


if guess > number:
print("Too high!")
else:
print("Too low!")
guess = int(input("Guess again: "))

print("You got it!")

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))

8.def is_anagram(str1, str2):


str1_sorted = sorted(str1.lower())
str2_sorted = sorted(str2.lower())
return str1_sorted == str2_sorted

9. sentence = input("Enter a sentence: ")


words = sentence.split()
num_words = len(words)
print("The sentence has " + str(num_words) + " words.")

10. def average(numbers):


total = sum(numbers)
avg = total / len(numbers)
return avg

You might also like