Skip to main content

GRADE XI - PYTHON DICTIONARY

 PYTHON DICTIONARY 

PRACTICAL QUESTIONS 

IP - GRADE XI


Q1. WAP to create a dictionary containing names of competition winner students as KEY and number of their wins as values.


n=int(input("How Many Students ?")) 

compwinner={ }

for i in range(n):

    key=input("Enter Name of the Student:")

    value=int(input("Enter No of Wins:"))

    compwinner[key]=value

print("The Dictionary is:", compwinner)


Q2.WAP TO INPUT TOTAL NO OF SECTIONS AND STREAM IN 11TH CLASS AND DISPLAY ALL.

cxi={}

n=int(input("Enter n no of sections:"))

i=1

while i<=n:

    sec=input("Enter section:")

    stre=input("Enter Stream:")

    cxi[sec]=stre

    i+=1

print("class section  stream")

for i in cxi:

    print("XI", i , cxi[i])


Q3. WAP to create a dictionary containing roll number of students and percentage as

values for n number of students display the total number of students scoring more than 80

stud={ }# Empty dictionary created

n=int(input("enter mumber of students - "))

for i in range(n):

    rno = input("enter Roll No - ")

    stud[rno] = float(input("Enter percentage –"))

ctr=0

for rno in stud:

    if stud[rno]>80:

        ctr+=1

print("No. of students scoring percentage above 80 –" ,ctr)


Q4. Program to create a dictionary which stores names(key) of employees and their salary(value)


num = int(input("Enter the number of employees whose data to be stored: "))

count = 1

employee = {}

for count in range (num):

    name = input("Enter the name of the Employee: ")

    salary = int(input("Enter the salary: "))

    employee[name] = salary

    print("\n\nEMPLOYEE_NAME \tSALARY")

    

    for k in employee:

        print(k,'\t\t',employee[k])


Q5.Dictionary key pointing to different values

dic = {}

while True :

    nam = input("Enter name :-")

    phone = float(input("Enter phone number :-"))

    cost = float(input("Enter cost :-"))

    item = input("Enter item :-")

    dic[ nam ] = [ phone , item , cost ]

    a = input("Do you want to enter more records enter (Yes/ No) :- ")

    if a == "No" or a == "no":

        break

for i in dic :

    print()

    print("Name : ", i )

    print("Phone : ", dic[ i ][ 0 ] , "\t"

          , "Cost : ", dic[ i ][ 1 ] , "\t", 

          "Item : ",  dic[ i ][ 2 ])


Q6.Display product if present in the dictionary otherwise invalid message

dic = { }


while True :

    product = input("enter the name of product (enter q for quit )= ")

    if product == "q" or product == "Q" :

        break

    else :

        price = int(input("enter the price of product = "))

        dic [ product ] = price


while True :

    name = input("enter the name of product those you are 

                 entered (enter q for quit )= ")

    if name == "q" or name == "Q" :

        break

    else :

        if name not in dic :

            print("name of product is invaild")

        else :

            print("price of product = ",dic[name])

Q6. Write a Python program that accepts a value and checks whether the inputted value is part of given dictionary or not. If it is present, check for the frequency of its occurrence and print the corresponding key otherwise print an error message.

'''

dic = eval(input("Enter a dictionary :- "))

val = eval(input("Enter a value :-"))


lst = list( dic.values() )

if val in lst :

    print("Frequency of occurrence of ",val ," is ", lst.count( val ))

    print("Its key are :-" )

    for i in dic :

        if dic [i] == val :

            print(i)

else :

    print("Not found !!")

Comments

Popular posts from this blog

CS - SORTING/SEARCHING ALGORITHMS

  SORTING ALGORITHMS                       SORTING ALGORITHM PDF LINK #Bubble Sort          ·        The outer loop iterates through the entire array. ·        The inner loop compares adjacent elements and swaps them if they are out of order. ·        The outer loop runs n times, and each pass moves the largest element to its correct position. arr=[3,8,5,2,1] n = len(arr) print(n) for i in range(n):  #traverse through all the elements         # Last i elements are already sorted, no need to check them         for j in range(0, n-i-1):              # Swap if the element found is greater than the next element              if arr[j] > arr[j+1]:               ...

GRADE XI - NESTED FOR LOOP

                                                         NESTED FOR LOOP 1. for var1 in range(3):      print(var1,"OUTER LOOP")          # 0 outer loop       1 outer loop      2 outer loop          for var2 in range(2):                  print(var2+1,"INNER LOOP")    #1  2 inner loop     1  2  inner loop   1 2 inner loop  2. Print the following pattern using for loop: 1  1 2  1 2 3  1 2 3 4  Sol: for r in range(1,5):   #ROWS     for c in range(1,r+1):   #COLUMNS         print(c,end=" ")     print() 3. Print the following pattern using for loop: @  @ @  @ @ @...