AI Experiment 1
AI Experiment 1
(UNC504P)
Experiment No. 1
Basics of Python
1. Given two lists—one containing keys and the other containing values. Create a
dictionary by pairing corresponding elements from both lists.
Ans.
2. Write a program that compares two numbers and prints whether they are equal,
not equal, greater than, or less than each other.
Ans.
3. Create a list of length 10 of your choice containing multiple types of data. Using
for loop print the element and its data type.
Ans.
4. Using a while loop, verify if the number A is purely divisible by number B and if
so then how many times it can be divisible.
Ans.
5. Create a list containing 25 integer type data. Using for loop and if-else condition
print if the element is divisible by 3 or not.
Ans.
6. Given a list my list = [1, 2, 3, 4, 5], write the code to slice the list and obtain the
sub-list [2, 3].
Ans.
Ans.
8. Calculate the multiplication and sum of two numbers: Given two integer numbers,
return their product only if the product is equal to or lower than 1000. Otherwise,
return their sum.
Ans.
9. Write a program to iterate through the first 10 numbers, and in each Print charac-
ters from a string that are present at an even index number. Accept a string from
the user and display characters that are present at an even index number.
Ans.
10. Write a program to iterate through the list and find the even number & its count.
Ans.
11. Write a program to find the minimum value of a list of numbers 5,3,8,-1,-2.2,0
(Don’t use built in function).
Ans.
12. Write a programme to iterate over a list of strings and check whether a particular
word is in or not?
Ans.
13. Write a programme that uses a while loop to test whether user input a password
”Secret” other wise print ” Your password is incorrect”.
Ans.
15. Write a programme that asks the user for number (int) . It computes the average
of a number & allows the user to enter -1 to quit.
Ans.
16. Write a programme with function get factor that takes an integer as a parameter
and return a list of factors of that number.
Ans.
17. Write a program with a function unique list that takes a list of numbers as a
parameter and return a new list with the unique list.
Ans.
18. Write a programme to create a dictionary of three students with their details like
name,grades & attendance of 5 subjects in list. Then create another dictionary
which is having roll no as keys and name of the students as values. Write another
programme to get average of all the marks.
Ans.