Some Simple Python Programs with Output

Q1: You are working in a bank and you have been given two lists of the employees who worked in 2021. Employee’s name in list 1 are Ramesh, Suresh, Mahesh, Ali, Jacob and Saritha. List 2 contains the names of Ali, Mukesh, Mahesh, Jacob, Sai, Sarita. Please write a program which helps to identify people who are common in both lists. Please do not use any in-built function.

Program –  

list1 = ["mahesh", "suresh", "ali", "jacob", "saritha"]
list2 = ["ali", "mukesh", "mahesh", "jacob", "sai", "sarita"]

for i in list1:
   if i in list2:

Output –


Q2: While entering data, someone entered a few names as a common string “Ramesh Suresh Mohit”. Please write a program which separates all the names and convert them into a list. Once converted in a list, please write a program which adds their age. 

Ramesh : 25 
Suresh : 22 
Mohit : 26

Program – 

names_string = "Ramesh Suresh Mohit"
names_list = names_string.split()
ages = {
    "Ramesh": 25,
    "Suresh": 22,
    "Mohit": 26
total_age = 0

for name in names_list:
    if name in ages:
        total_age += ages[name]

print(f"Total Age: {total_age}")


['ramesh', 'suresh', 'mohit']
total_age: 73

Q3: A few students from a university have taken three exams

Name = Sam, Jacy, Tom, Steve
Python = 25, 26, 29, 28
Statistics = 23, 21, 19, 25
SQL = 29, 27, 28, 25

Please write a program which calculates mean values (no in-built function for mean) of all three tests and print the highest mean value. Addition and other functions are allowed. Please also report who scored the highest mark in python using programming construct.

Program –

Names = ['Sam', 'Jacy', 'Tom', 'Steve']
python = [25, 26, 29, 28]
stats = [23, 21, 19, 25]
sql = [29, 27, 28, 25]

#all three's mean value
python_mean = sum(python)/len(python)
stats_mean = sum(stats)/len(stats)
sql_mean = sum(sql)/len(sql)
print(f"python_mean = {python_mean}, stats_mean = {stats_mean}, sql_mean = 

#highest mean value
high_mean = max(python_mean, stats_mean, sql_mean)
print("High mean:", high_mean)

#highest marks in python
high_py_score = max(python)
high_py_stu = Names[python.index(high_py_score)]
print("Highest Python Score:", high_py_score, "by", high_py_stu)

Output –

python_mean = 27.0, stats_mean = 22.0, sql_mean = 27.25
High mean: 27.25
Highest Python Score: 29 by Tom

Q4: You are working in a medical store. A patient came to your medical store and asked to buy 2 strips of paracetamol, 3 strips of azithromycin and 5 strips of Vitamin C. One strip of paracetamol costs Rs 35, one strip of azithromycin costs Rs 49 and one strip of vitamin c costs Rs. 33. Patient gave you Rs 2000. Please tell us what is the total cost of each medicine, total cost of all medicine and how much money you refunded to the patient?

Program –

paracetamol = 2*35
azithromycin = 3*49
Vitamin_C = 5*33

print("total cost of paracetamol madicine: ", paracetamol)
print("total cost of azithromycin madicine =", azithromycin)
print("total cost of Vitamin_C madicine =", Vitamin_C)

total = paracetamol+azithromycin+Vitamin_C
print("total price of madicine =" + str(total))

taken = 2000
given = 2000 - total
print("we have to give back amount is =" + str(given))

Output –

total cost of paracetamol madicine: 70
total cost of azithromycin madicine = 147
total cost of Vitamin_C madicine = 165
total price of madicine =382
we hive to give back amount is =1618

Q5: Accept a sentence as input and find the number of vowels in it. Assume that the sentence has no punctuation marks. For example: I am learning python contains 6 vowels. This function should be applicable for all other different sentences.

Program –

sentence = str(input())
vowel = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
count = 0

def vowels(a):
   global count
   for i in a:
       if i in vowel:
           count += 1

Output –

hello world

Q6: You have been appointed by the election commission to create a website. Your first task is to work on a program which tells candidates if they are eligible for voting or not. If they are eligible your output should be ‘Congrats! You are eligible’, otherwise it should tell that you have to return after X number of years. Eligibility criteria for voting is 18 years.

For example, If someone is 18 or above your output should be ‘Congrats! You are eligible’. If someone’s age is 15 years it should print output as ‘return after 3 years’.

Program – 

age = int(input())

if age >= 18:
     print("Congrats! You are eligible.")
     print(f"return after {18- age} years.")

Output –

return after 5 years.

Read This

Leave a Comment

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

Scroll to Top