CodeTantra Python Programming L7 Solution

In this blog post, you will find all the Solutions to the L7 questions of the Codetantra Python Programming Course. Here are the answere to these question:-

Codetantra python programming L7

Q1:- L7/Dictionaries/Introduction to Dictionary :- Select all the correct statements from the given options.

Dictionary is a Python data type to store multiple values.

We use parenthesis 0 to define a dictionary.

In dictionary we represent an element in the (key-value) format.

Keys of the dictionary cannot be changed.

dictionary() function is used to create an empty dictionary.

Q2:- L7/Dictionaries/Accessing Elements of Dictionary :- Write the missing code in the program to retrieve the elements of the dictionary using keys.

mydict ={“name”: “Rama”, “branch”:”CSE”, “place”:”HYD”}

# Print the values of dictionary using keys

 

print(mydict[“name”])

print(mydict[“branch”])

print(mydict[“place”])

Q3:- L7/Dictionaries/Understanding Dictionary :- Identify the errors in given program and correct the program.

mydict={ “game”: “chess”, “dish”:”chicken”, “place”:”home”}

 

print (mydict[“game”])

print (mydict[‘dish’])

print(mydict[“place”])

 

mydict[“game”]= “cricket”

print (mydict[“game”])

Q4:- L7/Data Type Conversions/Data Type Conversion :- Write a simple program to convert given number into string char and hexadecimal and complex number.

a = int(input(“Enter a value: “))
b= int(input(“Enter b value: “))

 

#print a value respective string

print(a)

 

# print a value respective char

print(chr(a))

 

# print a value respective hexadecimal value
print(hex(a))

 

#print a and b of complex number
print(complex (a,b))

Q5:- L7/Data Type Conversions/Data Type Conversions :- Write the missing code in the given program to convert two lists into one dictionary and convert the dictionary into the set. Follow the instructions given as comment lines in the program

list1 = [“key”,”key2″,”key3″]

list2 = [“value1”, “value2”, “value3”]

 

print(list1)

print(list2)

mydict=zip(list1,list2)

# using zip() function we can create dictionary with two Lists (one List)

 

#convert dictionary into set using set() method

set1= set(mydict)

 

#print elements in sorted order

list3=list(set1)

print(sorted(list3))

Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible. Till then check out our more blog posts.

Leave a Comment

Your email address will not be published. Required fields are marked *