AI Project
AI Project
ARTIFICIAL INTELLIGENCE
Practical Questions (To be done in the Practical Journal)
1. If you were in the place of this developer and if there was no other alternative to the situation, which
one of the two would you prioritise and why?
2. Let us now assume that the car has hit the boy who came in front of it. Considering this as an accident,
who should be held responsible for it? Why?
a. The person who bought this car
b. The Manufacturing Company
c. The developer who developed the car’s algorithm
d. The boy who came in front of the car and got severely injured
Practical 3: AI Bias
Another aspect to AI Ethics is bias. Everyone has a bias of their own no matter how much one tries to be
unbiased, we in some way or the other have our own biases even towards smaller things. Biases are not
negative all the time. Sometimes, it is required to have a bias to control a situation and keep things
working.
When we talk about a machine, we know that it is artificial and cannot think on its own. It can have
intelligence, but we cannot expect a machine to have any biases of its own. Any bias can transfer from the
developer to the machine while the algorithm is being developed.
1. Majorly, all the virtual assistants have a female voice. It is only now that some companies have
understood this bias and have started giving options for male voices but since the virtual assistants came
into practice, female voices are always preferred for them over any other voice. Can you think of some
reasons for this?
2. If you search on Google for salons, the first few searches are mostly for female salons. This is based on
the assumption that if a person is searching for a salon, in all probability it would be a female. Do you
think this is a bias? If yes, then is it a Negative bias or Positive one?
Practical 4: AI Access
Since Artificial Intelligence is still a budding technology, not everyone has the opportunity to access it.
The people who can afford AI enabled devices make the most of it while others who cannot are left
behind. Because of this, a gap has emerged between these two classes of people and it gets widened with
the rapid advancement of technology. Let us understand this with the help of some examples:
AI creates unemployment
AI is making people’s lives easier. Most of the things nowadays are done in just a few clicks. In no time
AI will manage to be able to do all the laborious tasks which we humans have been doing since long.
Maybe in the coming years, AI enabled machines will replace all the people who work as labourers. This
may start an era of mass unemployment where people having little or no skills may be left without jobs
and others who keep up with their skills according to what is required, will flourish.
This brings us to a crossroads. On one hand where AI is advancing and improving the lives of people by
working for them and doing some of their tasks, the other hand points towards the lives of people who are
dependent on laborious jobs and are not skilled to do anything else.
AI for kids
A young boy in class 3 has got some Maths homework to finish. He is sitting at a table which has the
chatbot - Alexa on it, and he is struggling with his homework. Soon, he starts asking Alexa to answer all
his questions. Alexa replies with answers and the boy simply writes them down in his notebook.
x=2
while x<=10:
print(x)
x=x+1
output: 2
3
4
5
6
7
8
9
10
marks = 60
if marks > 75:
print("You get an A grade")
elif marks > 60:
print("You get a B grade")
else:
print("You get a C grade")
4. Write a program to input temperature and check if the weather is hot, moderate or cold.
# Code to input temperature and check if the weather is hot, moderate or cold.
temp = float(input("enter temperature in °Celcius: ")) # User inputs temperature in celcius
if temp > 35: # Check if temp > 35 or not
print("Weather is hot.")
# If temperature is not greater than 35, then it is either lesser than or equal to 35. Let us again use the
# alternative conditional statement - the elif condition here.
elif temp >= 20:
print("Weather is moderate.")
# If none of the above conditions stands true, the else statement executes.
else:
print("Weather is cold.")
# Now, according to the average marks obtained, the grades are to be assigned.
# Note that any average can just have one type of grade. Hence, if-elif-else ladder will be used here.
if average > 80:
grade = 'A'
7. Write the Python program to check the number entered is positive, negative or zero.
(Nested if Example)
8. Write a program to find the sum of all numbers stored in a list. (Python for Loop)
# List of numbers
numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11]
# variable to store the sum
sum = 0
# iterate over the list
for val in numbers:
sum = sum+val
# Output: The sum is 48
print("The sum is", sum)
9. Write a program to add natural numbers upto a user entered number. (Python while Loop)
# sum = 1+2+3+...+n
# To take input from the user,
# n = int(input("Enter n: "))
n = 10
# initialize sum and counter
sum = 0
i=1
while i <= n:
sum = sum + i
i = i+1 # update counter
# print the sum
print("The sum is", sum)
for j in range(5): # This is a nested loop as tand comes under the other loop
print ("j = ",j) # This print statement is under the nested loop
print("end of i = ",i)
print("end of nested for loops")
In the above code, for each iteration of for i block, a whole for j block is ran. this can be further nested to
as many nests as we want. Note that indentation plays a very important role in this. Changing the
indentation will result in unexpected answers or might throw an error.
12. Write programs to print the following patterns:
1
12
123
1234
12345
# A matrix is formed using 2 dimensions. To work in 2 dimensions, we need two loops working together i
n a nested looping configuration.
# Outer loop handles the number of rows
for i in range(1,6): # Loop runs from 1 to 5
# Inner loop to handle number of columns
for j in range(1, i + 1): # Loop runs from 1 to i+1
print(j, end = " ") # Print statement executes inside the nested loop
print() # Once the inner loop gets executed, code reaches to new line with this empty print command
******
*
**
***
****
*****
****
***
**
*
# In this code, two nested loops will be used: one for the increasing triangle and other for the decreasing tr
iangle
for i in range(1,6):
for j in range(1, i + 1):
print("*", end = " ")
print()
for i in range(1,5):
i=5-i
for j in range(1, i + 1):
print("*",end = " ")
print()
******
# In this code, read a number and print a right triangle using "*".
*
**
***
****
*****
n=int(input("Enter the number : "))
if n==0:
print("Enter a valid number.")
for x in range(1,n+1):
print("*" * x)
print("\n")
i=1
while i <= 100: # Loop starting from 1 till 100
if i % 3 == 0 and i % 2 == 0: # Check if the number is divisible by both 2 and 3to chec-
#-k its divisibility by 6
print(i," is divisible by 6") # Execute when the if statement is true
i=i+1 # Increment the variable for next iteration
16. Complete the code given below. Fill in the blanks to find the average percentage of a class with 1
5 students whose marks are given in the list marks.
marks = [40,54,81,95,76,69,35,63,99,58,73,85,56,62,93]
sum = 0 # Variable Intitiation
average = 0 # Variable Intitiation
for m in marks: # Loop statement to run through 15 student's marks
sum=sum+m # Statements to calculate average % of a class of 15 students
average = sum/15 # Calculate average percentage of the class
print(average) # Print average percentage
Output: 69.26666666666667
PYTHON LISTS
List= ['G','O','O','D','M','O','R','N','I','N','G']
print(List)
print(List[3:8])
print(List[5:])
print(List[:])
print(List[:-7])
print(List[-6:-1])
print(List[::-1])
Answers:
['G', 'O', 'O', 'D', 'M', 'O', 'R', 'N', 'I', 'N', 'G']
['D', 'M', 'O', 'R', 'N']
['O', 'R', 'N', 'I', 'N', 'G']
['G', 'O', 'O', 'D', 'M', 'O', 'R', 'N', 'I', 'N', 'G']
['G', 'O', 'O', 'D']
['O', 'R', 'N', 'I', 'N']
['G', 'N', 'I', 'N', 'R', 'O', 'M', 'D', 'O', 'O', 'G']
18. What are the three methods to add elements to the List. Give examples for each.
We can add elements to any list using the following three methods :
1) append() method- Adds an element to the end of the List. Other lists can also be added.
List = []
List2 = ['Good', 'Morning']
List.append(1)
List.append(2)
List.append(List2)
print(List)
Output: [1, 2, ['Good', 'Morning']]
List = [1,2,3,4]
List.insert(3, 12)
List.insert(0, 'Kabir')
print(List)
Output: ['Kabir', 1, 2, 3, 12, 4]
3) extend() method- Add multiple elements at the same time at the end of the list.
List = [1,2,3,4]
List.extend([8, 'Artificial', 'Intelligence'])
print(List)
2) pop() method -Removes and returns an element from given index, otherwise removes the last element.
List = [1,2,3,4]
List.pop()
print(List)
List.pop(1)
print(List)
Output: [1, 2, 3]
[1, 3]
20. Write a program to print numbers from the list. ( test_list = [2,4,6,8,10] )
test_list = [2,4,6,8,10] # Sample list, (sequence = list of numbers)
for i in test_list: # elements of this list will be printed till the list terminates
print(i)
21. Write a program to add 2 to each element of a list and print numbers from the list.
test_list = [1,4,8,16,-1]
for num in range( len(test_list) ): # len(list_name) gives us the length of the list.
test_list[num] = test_list[num] + 2
print(test_list)
22. Write a program to enter weight of 15 students. Find the lightest of all.
a = [] # Empty List
for i in range(15): # 15 students need to enter their weight. Therefore, the loop runs for 15 times.
a.append( int( input("Enter number " + str(i + 1) + ":") ) ) # Weights entered by the user are appended in
the empty list a one by one as the loop executes.
print(a) # Print the entered values
min = a[0] # Initiate a variable min with the first entry
for i in range(15): # The loop again iterates for 15 times to check which element is the smallest.
if a[i] < min: # If the element is less than the min value,
min = a[i] # min value is updated with the new smaller value.
print(min)
23. Write a program to find sum of 10 numbers in a list.
test_list = [1,8,29,-54,-77,29,15,38,49,-39] # Sample List
sum = 0 # Variable to store the sum of list elements
for num in test_list: # Each element of the list is called and the loop iterates for len(test_list) times
sum = sum + num # The element called is added to the sum variable. Like this, all the elements get
added upto the sum variable
print("sum of the list = ",sum)
**********