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

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XII - CSV FILE

CSV FILE (COMMA SEPERATED VALUE) CSV NOTES LINK :  CSV NOTES - CLICK HERE Writing data to a CSV file involves the following steps: Import the csv module Open the CSV file in write mode ( "w" ) using open() Create the writer object Write the data into the file using the writer object Close the file using close() writerow() Method This method is used to write a single row to a CSV file. It takes a sequence (list or tuple) as its parameter, and writes the items as a comma-separated line in the file. You do not need to add a newline character (\n) — it automatically places the end-of-line marker.     EXAMPLE 1: import csv  # Importing the csv module # CSV file opened using relative path csv_fobj = open("emp.csv", "w")   # Writer object created wtr_obj = csv.writer(csv_fobj) # Record with field heading is written wtr_obj.writerow(["Empno", "Name", "Salary"]) # Records with data are...