You are on page 1of 5

Artificial Intelligence with Python B2

Assessment
1.import mathuser_input = [4, 18, 16, 25]
sqare_roots = [math.sqrt(num) for num in user_input]
print(sqare_roots)

[2.0, 4.242640687119285, 4.0, 5.0]

2.def divisible_by_3_and_5():
for num in range(1, 101):
if num % 3 == 0 and num % 5 == 0:
print(num)

3-def check_vowel_or_consonant(letter):
vowels = 'aeiouAEIOU'
if letter in vowels:
print(f"{letter} is a vowel.")
else:
print(f"{letter} is a consonant.")

4-char1 = chr(40)
char2 = chr(170)

distance = abs(ord(char1) - ord(char2))


print(f"Distance between '{40}' and '{170}' is {distance}.")

5- def count_vowels(input_string):
vowels = 'AEIOUaeiou' # All uppercase and lowercase
vowels
vowel_count = sum(1 for char in input_string if char in
vowels)
return vowel_count

input_string = "ABCDEFGHIJKLMNO"
result = count_vowels(input_string)
print(f"The number of vowels in the string is: {result}")

6- # Uppercase alphabets
print("Uppercase Alphabets:")
for i in range(65, 91): # ASCII codes for A-Z
print(chr(i), end=' ')

print("\n")
# Lowercase alphabets
print("Lowercase Alphabets:")
for i in range(97, 123): # ASCII codes for a-z
print(chr(i), end=' ')

7-def sum_even_numbers(lst):
total = sum(num for num in lst if num % 2 == 0)
print(f"Sum of even numbers in the list: {total}")

8- numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Sample list of


numbers

# Print squares of numbers excluding factors of 3


for num in numbers:
if num % 3 != 0: # Exclude numbers that are factors of 3
square = num ** 2
print(f"Square of {num} is {square}")
9- string1 = "ALICE,ARICA,ANTARCTICA,AROMA"
string2 = "America,Australia,Africa,Amazon"

# Replace all 'A's with 'a's in both strings


string1 = string1.replace('A', 'a')
string2 = string2.replace('A', 'a')

# Concatenate the modified strings


concatenated_string = string1 + string2

print(concatenated_string)

10-numbers = [12, 170, 155, 73, 987, 144]


odd_numbers = [num for num in numbers if num % 2 != 0]

print(odd_numbers)

11- input_string = "aBcD"


output_string = 'AbCd'

for char in input_string:


if char.isupper():
output_string += char.lower()
else:
output_string += char.upper()

print(output_string)

You might also like