Python coding -Code gladitors

CODE MASTERS CLASS



 PYTHON CODING PART-6



#In this we will learn more programming on dictionary data type

Q.Write a program to print dictionary to find maximum and minimum value of the key and sum of the key values

""""WAP to print dictionary to find maximum and minimum value of the key and sum of the key values
"""
n=int(input("Enter  a number of friends: "))
dict={ }
for i in range(n):
    R=eval(input("Enter a roll number of the students:"))
    M=eval(input("Enter a marks of the students:"))
    dict[R]=M
print(dict)
m=max(dict)
n=min(dict)
sum=0
for keys in dict:
    sum=sum+dict[keys]



print("Maximum values of the key is:",m)
print("Minimum values of the keys is :",n)
print("sum of the values",sum)



OUTPUT:


Steps have to follow:
1) First you have to think and have to know about keywords and python grammer to write the first line that no. of students. 
2) In dictionary you

Q.WAP To  which accept SalesAmount from user then calculate and print discount amount per following criteria 

In this only you have to test a condition that is given by the user so for that you have to follow only 2 steps:
1)First you must you have to use input function to take input from the user if it is nummerical value then use before input function like int() ,or float() or eval() functions.
2)Second step to check condition using if, elif and else structure,,after that you just have to use print() function. 

""""WAP To  which accept SalesAmount from user then calculate and print discount amount per following criteria :
 Sales Amount                       Discount 
                         Less than 1000                    5% of Sales Amount
                         1001 to 3000                       7% of sales Amount
                         More than 3000                  10% of Sales Amount

"""
print("1.*****SALE SALE SALE *****")

salesamount=int(input("Enter a sales amount:"))
discount=0
if salesamount<1000:
    discount=5/100*salesamount
elif 1001<= salesamount>3000 :
    discount=7/100*salesamount
else:
    discount=10/100*salesamount
print(discount,"Discount on your purchase of",salesamount)



OUTPUT:





Q.Write a Python program to input 10 student names and their marks in a dictionary as a key value pair then print the names of those students who secures marks more than 60


In this you have to learn that how to make a dictionary but if you do not know lnow so worry about it ,here you can learn again .To do this program Just follow these steps :

1)First to use input() function to take input that how many students or employee are there  and run the program until number of not over.To take name  write just or use only input() function and input the marks of the students .
2)Now you have to convert into a dictionary form ,so take name of the students as a key and theirs marks as a its value.

3)Write a always this shortcut trick that is (dict[name]=marks  ) you can change like instead of name you can write any other thing or you can change the name of the dictionary that here used dict.

4)After that again you have to use loop to test the condition and then use print()  function.

""""
 Write a Python program to input 10 student names and their marks in a dictionary as a key value pair then print the names of those students who secures marks more than 60

"""
n=int(input("Enter a number of students:"))
dict={ }
for i in range(0,n):
    name=input("Enter a name of the students")
    marks=int(input("Enter a mark of the students:"))
    dict[name]=marks
print("Dictionary of the students and their marks:",dict)

for keys in dict:                          # this is called a range in which it will go to every key value
    if dict[keys]>60:                      #here it checks every key value it means every students marks 
    
    



        print(keys,end=' '" got above 60 marks   and  " )
    

        


OUTPUT:



Q.Write a program in python to input five state names and their capital in a Dictionary as a Key Value pair, then ask the user to enter state and print its capital if found in a dictionary, otherwise print message “State not found in dictionary”


"""
Write a program in python to input five state names and their capital in a Dictionary as a Key Value pair, then ask the user to enter state and print its capital if found in a dictionary, otherwise print message “State not found in dictionary”
"""
n=int(input("Enter a number of states:"))
dict={ }
for i in range(0,n):
    state=input("Enter a name of the states:")
    capital=input("Enter a capital of the state::")
    dict[state]=capital
print("Dictionary of the students and their marks:",dict)
State=input("Enter a state name to get its capital:")
for key in dict:
    if State in dict:
        print(dict[State],"is the capital of ",State)
    else:
        print('Your state not found')


                     
OUTPUT:



Python coding -Code gladitors Python coding -Code gladitors Reviewed by Shubham Prajapati on March 18, 2021 Rating: 5

No comments:

If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat

Powered by Blogger.