You are on page 1of 16

Program:

list1=[]

# asking number of elements to put in list

num = int(input("Enter number of elements in list: "))

# iterating till num to append elements in list

for i in range(1, num + 1):

print("Enter element",i,":")

element = int(input())

list1.append(element)

# print maximum element

print("Largest element is:", max(list1))

# print minimum element

print("Smallest element is:", min(list1))

Output:

Enter number of elements in list: 4

Enter element 1 :

12

Enter element 2 :

Enter element 3 :

10

Enter element 4 :

Largest element is: 12

Smallest element is: 5


Program:

list1=[]

tuple1 = tuple(input("Enter a string: "))

for i in range (0,len(tuple1)):

val=tuple1[i]

if (val not in list1 ):

print("Number of times",val, "appears in the string is",tuple1.count(val))

list1.append(val)

Output:

Enter a string: abracadabra

Number of times a appears in the string is 5

Number of times b appears in the string is 2

Number of times r appears in the string is 2

Number of times c appears in the string is 1

Number of times d appears in the string is 1

Enter a string: **hello**

Number of times * appears in the string is 4

Number of times h appears in the string is 1

Number of times e appears in the string is 1

Number of times l appears in the string is 2

Number of times o appears in the string is 1


Program:

val=eval(input("Enter a list: "))

print("Original list is:",val)

s=len(val)

if s%2!=0:

s=s-1

for i in range(0,s,2):

val[i],val[i+1]=val[i+1],val[i]

print("List after swapping is:",val)

Output:

Enter a list: [10,5,40,24]

Original list is: [10, 5, 40, 24]

List after swapping is: [5, 10, 24, 40]

Enter a list: [1,2,3,4,5,6,7]

Original list is: [1, 2, 3, 4, 5, 6, 7]

List after swapping is: [2, 1, 4, 3, 6, 5, 7]


Program:

print("Enter the size of list: ", end="")

tot = int(input())

print("Enter", tot, "elements: ", end="")

x = []

for i in range(tot):

x.append(input())

print("\nThe list is:")

print(x)

print("\nEnter an element to search: ", end="")

element = input()

if element in x:

print("\nIt is available in the list")

else:

print("\nIt is not available in the list")


Output:

Enter the size of list: 4

Enter 4 elements: 12

14.67

computer

45

The list is:

['12', '14.67', 'computer', '45']

Enter an element to search: 14.67

It is available in the list

Enter the size of list: 2

Enter 2 elements: 10

20

The list is:

['10', '20']

Enter an element to search: 30

It is not available in the list


Program:

alpha = ('a', 'b', 'c', 'd', 'e', 'f','g','h','i', 'j', 'k', 'l', 'm', 'n','o','p','q', 'r', 's', 't', 'u', 'v','w','x','y', 'z')

vow = input("Enter a vowel:")

if (vow=='a' or vow=='e' or vow=='i' or vow=='o' or vow=='u'):

index = alpha.index(vow)

print("The index of the entered vowel in the alphabets is",index)

print("The position of the entered vowel in the alphabets is",index+1)

else:

print("We accept only small cased vowels as input")

Output:

Enter a vowel:i

The index of the entered vowel in the alphabets is 8

The position of the entered vowel in the alphabets is 9

Enter a vowel:p

We accept only small cased vowels as input


Program:

list_score_A=[]

list_score_B=[]

count_A=0

count_B=0

for i in range(3):

tot = print("Enter the score of team A in round",i+1)

list_score_A.append(input())

tot = print("Enter the score of team B in round",i+1)

list_score_B.append(input())

if (list_score_A==list_score_B):

print("The match ends in draw!")

else:

for j in range(3):

if(list_score_A[j]==list_score_B[j]):

print("Its a tie in round",j+1)

continue

list_score_A[0]=list_score_A[j]

list_score_B[0]=list_score_B[j]

if(list_score_A>list_score_B):

print("Team A wins in round",j+1)

count_A=count_A+1
elif(list_score_A<list_score_B):

print("Team B wins in round",j+1)

count_B=count_B+1

else:

print("Its a tie in this round!")

if(count_A>count_B):

print("Team A wins the match!")

elif(count_A<count_B):

print("Team B wins the match!")

else:

print("The match ends in draw!")

Output:

Enter the score of team A in round 1

Enter the score of team B in round 1

Enter the score of team A in round 2

Enter the score of team B in round 2

Enter the score of team A in round 3

Enter the score of team B in round 3


2

Team B wins in round 1

Team B wins in round 2

Team A wins in round 3

Team B wins the match!

Enter the score of team A in round 1

Enter the score of team B in round 1

Enter the score of team A in round 2

Enter the score of team B in round 2

Enter the score of team A in round 3

Enter the score of team B in round 3

Team B wins in round 1

Its a tie in round 2

Team A wins in round 3

The match ends in draw!


Program:

n=int(int(input("Enter the number of students: ")))

d={}

yes=1

for i in range(n):

print("Please enter the details of student",i+1)

roll_no=int(input("Roll no: "))

name=input("Name: ")

marks=int(input("Marks: "))

d[roll_no]=[name,marks]

print("The student(s) who scored above 75 are: ")

for k in d:

if(d[k][1]>75):

yes=0

print(d[k][0])

if(yes==True):

print("-----")

Output:

Enter the number of students: 3

Please enter the details of student 1

Roll no: 5

Name: xxxxx

Marks: 90
Please enter the details of student 2

Roll no: 7

Name: zzzzz

Marks: 65

Please enter the details of student 3

Roll no: 6

Name: yyyyy

Marks: 82

The student(s) who scored above 75 are:

xxxxx

yyyyy

Enter the number of students: 2

Please enter the details of student 1

Roll no: 16

Name: aaaaaa

Marks: 70

Please enter the details of student 2

Roll no: 24

Name: bbbbb

Marks: 75

The student(s) who scored above 75 are:

-----
Program:

n=int(int(input("Enter the number of employees: ")))

d={}

for i in range(n):

print("Please enter the details of employee",i+1)

emp_no=int(input("Emp_No: "))

emp_name=input("Emp_Name: ")

salary=int(input("Salary: "))

d[emp_no]=[salary,emp_name]

l=sorted(d.values(),reverse=True)

print("The list of employees from highest salaried:")

for j in l:

print(j[1])
Output:

Enter the number of employees: 4

Please enter the details of employee 1

Emp_No: 12

Emp_Name: aaaa

Salary: 45000

Please enter the details of employee 2

Emp_No: 1

Emp_Name: yyyy

Salary: 32500

Please enter the details of employee 3

Emp_No: 6

Emp_Name: xxxx

Salary: 20000

Please enter the details of employee 4

Emp_No: 38

Emp_Name: bbbb

Salary: 50000

The list of employees from highest salaried:

bbbb

aaaa

yyyy

xxxx
Program:

import math

import statistics

numbers_list=[90,10,12,35,4,15,10,16,10,10]

print("The value of 2^8: " + str(math.pow(2, 8)))

print("Square root of 625: " + str(math.sqrt(625)))

print("The value of 5^e: " + str(math.exp(5)))

print("The value of log(625), base 5: " + str(math.log(625, 5)))

print('The Floor value of 6.25 are:' + str(math.floor(6.25)))

print('The Ceiling value of 6.25 are: ' + str(math.ceil(6.25)))

print('Absolute value of -94 and 54 are: ',str(math.fabs(-94)),str(math.fabs(54)))

print("The value of sin(45 degree): " + str(math.sin(math.radians(45))))

print("The mean of 90,10,12,35,4,15,10,16,10,10: " + str(statistics.mean(numbers_list)))

print("The median of 90,10,12,35,4,15,10,16,10,10: " +


str(statistics.median(numbers_list)))

print("The mode of 90,10,12,35,4,15,10,16,10,10: " + str(statistics.mode(numbers_list)))


Output:

The value of 2^8: 256.0

Square root of 625: 25.0

The value of 5^e: 148.4131591025766

The value of log(625), base 5: 4.0

The Floor value of 6.25 are:6

The Ceiling value of 6.25 are: 7

Absolute value of -94 and 54 are: 94.0 54.0

The value of sin(45 degree): 0.7071067811865475

The mean of 90,10,12,35,4,15,10,16,10,10: 21.2

The median of 90,10,12,35,4,15,10,16,10,10: 11.0

The mode of 90,10,12,35,4,15,10,16,10,10: 10


Program:

import random

while(True):

choice=input("Enter 'r' to roll dice or press any other key to quit: ")

if(choice!="r"):

break

n=random.randint(1,6)

print(n)

Output:

Enter 'r' to roll dice or press any other key to quit: r

Enter 'r' to roll dice or press any other key to quit: r

Enter 'r' to roll dice or press any other key to quit: r

Enter 'r' to roll dice or press any other key to quit: r

Enter 'r' to roll dice or press any other key to quit: r

Enter 'r' to roll dice or press any other key to quit: q

You might also like