Q6 rgeeeeeeeeeeeeeeeeeeeeeeeeeeeunlasfeuykanfyhawughnejnqwekluriryjqwkdjeydkqwreyfqwetguifyitfgquioygwetfgwe weqgbjdnkegyrjhmgykktw 3e444ee2jtyrbsvefsmse

 

  P.I.P:- 9.1

 

Q1. Suppose that D is the dictionary {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}. Write down what the value of D is after each of the following Python statements. Evaluate each statement starting with the same value of the dictionary D, mentioned above and write what will be the change dictionary D?

 

(a) D ["what"] = D ["are"]

(b) D.update ({"Sunday":25, "what":5})

(c) del D["you"]

(d) D ["which"] = 19

(e) D.clear ()

 

Answer =

 

(a)

>>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}

>>> D ["what"] = D ["are"]

>>> D

{'what': 11, 'are': 11, 'you': 14, 'doing': 5, 'next': 9, 'Saturday?': 4}

>>> 

 

(b)

>>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}

>>> D.update ({"Sunday":25, "what":5})

>>> D

{'what': 5, 'are': 11, 'you': 14, 'doing': 5, 'next': 9, 'Saturday?': 4, 'Sunday': 25}

>>> 

 

(c)

>>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}

>>> del D["you"]

>>> D

{'what': 22, 'are': 11, 'doing': 5, 'next': 9, 'Saturday?': 4}

>>> 

 

(d)

>>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}

>>> D ["which"] = 19

>>> D

{'what': 22, 'are': 11, 'you': 14, 'doing': 5, 'next': 9, 'Saturday?': 4, 'which': 19}

>>> 

 

(e)

>>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}

>>> D.clear ()

>>> D

{}

>>> 

 

 

 

 

 

Q4. Predict the output of the following code:

 

birthday = {

    'Newton' : 1642,

    'Darwin' : 1809,

    'Turing' : 1912

}

 

print ('keys :', birthday.keys())

print ('values :', birthday.values())

print ('items:', birthday.items())

print ('get:', birthday.get('Curie', 1867))

 

temp = {

    'Curie' : 1867,

    'Hopper' : 1906,

    'Franklin' : 1920

}

 

birthday.update(temp)

print ('after update:', birthday)

 

birthday.clear()

print ('after clear:', birthday)

 

Answer =

 

Output:-

 

keys : dict_keys(['Newton', 'Darwin', 'Turing'])

values : dict_values([1642, 1809, 1912])

items: dict_items([('Newton', 1642), ('Darwin', 1809), ('Turing', 1912)])

get: 1867

after update: {'Newton': 1642, 'Darwin': 1809, 'Turing': 1912, 'Curie': 1867, 'Hopper': 1906, 'Franklin': 1920}

after clear: {}

>>> 

 

 

 

 

 

 

 

Q5. Write a program that uses a dictionary that contains ten usernames and passwords. The program should ask the user to enter their usernames and passwords. If the username is not in the dictionary, the program should indicate that the person is not a valid user of the system. If the username is in the dictionary, but the user does not enter the right password, the program should say that the password is invalid. If the password is correct, then the program should tell the user that they are now logged into the system.

 

Answer =

 

dic = {'Path' : "2003",

       'wala' : "1809",

       'Portal' : "1912",

       'Express' : "2003",

       'Computer' : "9834",

       'Python' : "1990",

       'Mysql' : "2001",

       'c++' : "1996",

       'java' : "1998",

       'html' : "1999" }

 

username = input("Enter username :- ")

 

if username in dic :

    password = input("Enter password :- ")

    if dic[username] == password :

        print ("You are now logged into the system.")

    else :

        print ("Invalid password.")

else :

    print ("You are not valid user.")

Comments

Popular posts from this blog

Q 7 jrgeshestm teejthjkljklh srthklkltjsjkghsegbn tjhrhrthgkjerjklhbgebgjasb nerjks

Q4

q5 kjhgtishtglrhtvthghdghnnvcmnzbsd,nbdn neffjkghklen h