Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q/ using python answer the follwing parts : Part 1 For this part of the lab, wri

ID: 3594194 • Letter: Q

Question

Q/ using python answer the follwing parts :

Part 1 For this part of the lab, write code to iterate over all multiples of 3 between 0 and 100 (inclusive), and print the ones that are divisible by 2. Use the range() function to obtain a list of multiples of 3 between 0 and 100. Note: To determine if a number is divisible by 2, use the modulus operator (%) which returns the remainder after dividing two numbers. For example: >>> 100 % 10 >>> 97 % 1 7 Part 2 For this part of the lab, write code to check to see if an element, stored in a variable toFind, exists somewhere in the list. Print out the index of the element, if it exists in the list, and the message "The element does not exist in the list," otherwise.

Explanation / Answer


#part1
#create a list of multiples of 3
#between 0 and 100
multiples=range(0,100,3)
#checking if val is divisible by 2
#print to console
for val in multiples:
      if val%2==0:
            print(val)

Sample Output:
0
6
12
18
24
30
36
42
48
54
60
66
72
78
84
90
96

--------------------------------------------------------
#part2
#create a list of 5 numbers
alist =[1,2,3,4,5]
print(alist)
#prompt for user input
value=int(input('Enter element to find : '))
index=-1
found=False
#iterate over alist
for key in alist:
      #index=index+1
      index=index+1
      if key==value:
            found=True
            break                
#checking index is not -1         
if found ==False or index==-1:
      print('The element does not exist in the list')    
else:
      print(index)
    

Sample output:
>>>
[1, 2, 3, 4, 5]
Enter element to find : 5
4
>>> ================================ RESTART ================================
>>>
[1, 2, 3, 4, 5]
Enter element to find : 1
0
>>> ================================ RESTART ================================
>>>
[1, 2, 3, 4, 5]
Enter element to find : 3