Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please answer the questions based on the images given thank you. #imports and variables from random import randint pm = 'justin pierre james trudeau' instructor
please answer the questions based on the images given thank you.
\#imports and variables from random import randint pm = 'justin pierre james trudeau' instructor = 'John Doe' harry = "You've gotta ask yourself a question: how are you today?" numbers = [randint(5, 10) for _ in range(20)] \#creating set from the variable instructor s = set(instructor) print(s) \# adding 'z' to the set and print it s.add('z') print(s) \# using remove() method to take - from set s.remove(' ') print(s) \#using update() method to z y z. s. update('x', 'y', 'z') print(s) \#using len() function to get the number of elements in the set print(len(s)) \#create tuple from variable pm. t = tuple(pm) print(t) \#count \#create tuple from variable pm. t= tuple (pm) print(t) \#write the statement to produced the following lines \#count print("There are \{\}es in the tuple". format(t.count(' e)) ) \#index print("you can find a at index 15 of tuple". format(t.index('a' ) )) \#len print("There are \{\} elements in the tuple".format(len(t))) \#use array like indexing tool to print hello world print(t[2]) print(t[4]) \#create list from the variable harry harry="tom, wales, hanry, question" \#\#variable declaration with some data harry=harry.split(',') \#\# Using split method and print print("List after split method:- ", harry, end=" ") harry.append('Eastwood') \#\#Append method to add Eastwood print("List after append: - ", harry, end=' ) harry.insert( , 'Clint') \#\# Insert at begining print("List after insert:- ", harry, end=' ) harry. remove('question') \#\# Removing data print("List after remove: - ", harry, end=' ) hr=["Dirty", "Harry" ] harry. extend(hr) \#\#Extending the list print("List after extend: - ", harry, end=' ) harry.sort() \#\#Sorting the list harry . reverse()\#\#Reverse the list print("List after reverse:- ", harry, end=' ) \#\# creating dictionary with the given keys and values d={3462: 'Artificial Intelligence', 3468: 'Software Engineering Technician', 3469: 'Software Engineering Technology', 3472: 'Artificial Intelligence', 3478: 'Software Engineering Technician(FT)', 3528: 'health Informatics Technology(FT)', 3609: 'Game-Programing', 3668: 'Health Infromatics Technology', 3679: 'Game-Programming(FT)' 3 print("Dictionary: - ", d, end=' ) \#printing the complete dictionary print("Keys of dictionary: - ", d.keys(), end=' )\#Printing only keys print("Values of dictionary: - ", d.values(), end=' \ ') \#printing values only print("Find using Key Index: - ", list(d.values()) [list(d.keys()).index(3462)], Using the enumerate function This function can enumerate both sequences like sets, tuples, strings and lists as well as mappings like dictionaries The enumerate function returns a collection of tuples. Each tuples is a pair comprising of the index and the value. [ ] \# use the enumerate function to print each collection: set, tuple, list and dict \# You must print both the position and the item in the collection [ ] \# - 5 mark \# Use the items() method of the dict class to enumerate a dictionary \# You must print the position, the key and the valueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started