0% found this document useful (0 votes)
18 views

Mishthi (Roll No-05)

The document contains solutions to 25 programming questions in Python. It includes questions on basic concepts like data types, conditional statements, loops and functions. Some questions involve taking user input to check eligibility, find largest number, calculate tax etc. String, list and mathematical operations are also covered.

Uploaded by

Vijay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Mishthi (Roll No-05)

The document contains solutions to 25 programming questions in Python. It includes questions on basic concepts like data types, conditional statements, loops and functions. Some questions involve taking user input to check eligibility, find largest number, calculate tax etc. String, list and mathematical operations are also covered.

Uploaded by

Vijay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

COMPUTER SCIENCE

PROJECT

NAME-MISHTHI
CLASS-XI A
ROLL NO-05
Practical Questions:
Ques1- Write a program to check whether a person is above 18. If he/she is

above 18, the message should be you are above 18..


Input
Age=int(input("Enter the age of person:"))

if Age>18:
print("You are above 18")

elif Age==18:
print("You are currently 18")

else:
print("You are below 18")

Output

*Enter the age of person:18


You are currently 18

*Enter the age of person:35


You are above 18
*Enter the age of person:10

You are below 18

Ques2-Write a program to check eligibility to caste vote. Above 18 print


“eligible” or if not then “not eligible”..
INPUT
Age=int(input("Enter the age of a person:"))

if Age>=18:
print("You are eligible ")
else:

print("You are not eligible ")

Output
*Enter the age of a person:45

You are eligible


* Enter the age of a person:13

You are not eligible

Ques3. Write a program to print larger of two numbers ..


INPUT

num1=int(input("Enter the first number:"))


num2=int(input("Enter the second number:"))
if num1>num2:
print("num1 is greater")

else:
print("num2 is greater")

OUTPUT
*Enter the first number:56
Enter the second number:99
num2 is greater

*Enter the first number:67


Enter the second number:12
num1 is greater

Ques4. Write a program to find larger of three numbers..


INPUT
num1=int(input("Enter the first number:"))

num2=int(input("Enter the second number:"))


num3=int(input("Enter the third number:"))

if num1>num2 and num1>num3:


print("num1 is greater")

elif num2>num3 and num2>num1:


print("num2 is greater")

Else:
print("num3 is greater")
Output
*Enter the first number:45

Enter the second number:77


Enter the third number:98

num3 is greater
*Enter the first number:45
Enter the second number:99
Enter the third number:56

num2 is greater

Ques5. Write a program to display identity,type and value of different type of

variable we have learnt ....


INPUT

*Integer
x=45

print("Id of x is:",id(x))
print("Type of x is :",type(x))

*Float
y=35.5

print("Id of y is :",id(y))
print("Type of y is: ",type(y))

*String
z="Hello"
print("Id of z is :",id(z))
print("Id of z is :",type(z))
OUTPUT

Interger

Id of x is: 139706839979464
Type of x is : <class 'int'>
Float
Id of y is : 139706828840656
Type of y is: <class 'float'>

String
Id of z is : 139706829080944
Id of z is : <class 'str'>

Ques6.Write a program to check whether a number is even or odd..

INPUT
num1=int(input("Enter the Number:"))
if (num1%2)==0:

print("Even Number")
else:

print("Odd Number")
OUTPUT

*Enter the Number:45


Odd Number

*Enter the Number:45


Odd Number

Ques7.Write a program to accept marks of a student and display his/her grade .


If marks >85(grade A),70-85(grade B),60-70(grade C),45-60(grade D) and less

than 45(grade E)....


INPUT
def python():
perc=float(input("Enter the perc:"))
if perc>85 :

print('A')
elif perc>70 and perc<=85:
print('B')

elif perc>60 and perc<=70:


print('C')

elif perc>45 and perc<=60:


print('D')

else:
print('E')

OUTPUT
python()

Enter the perc:67


C

> python()
Enter the perc:49
D
> python()
Enter the perc:99

A
> python()

Enter the perc:77


B
> python()
Enter the perc:33

Ques8.W.A.P to accept salary of an employee and calculate tax amount . If

salary is >70000 tax is (8%) , 60000-70000 tax(7%) , 50000-60000 tax(6%) ,


less than 50000 (tax is 5% than salary )...

INPUT
def python():
salary=int(input("Enter salary of a person:"))

if salary>70000:
tax=0.08*salary

elif salary>60000 and salary<=70000:


tax=0.07*salary

elif salary>50000 and salary<=60000:


tax=0.06*salary

else:
tax=0.05*salary

print("Salary",salary,"Tax",tax)
OUTPUT

*python()
Enter salary of a person:65000

Salary 65000 Tax 4550.0


* python()
Enter salary of a person:45000
Salary 45000 Tax 2250.0

* python()
Enter salary of a person:22000
Salary 22000 Tax 1100.0

Ques9.Write a program to check whether a number is positive , negative and


zero...

INPUT
def python():

num1=int(input("Enter the Number:"))


if num1>0:

print("num1 is Even")
elif num1==0:

print("num1 is Zero")
else:

print("num1 is Odd")
OUTPUT
*python()
Enter the Number:45
num1 is Even

* python()
Enter the Number:0

num1 is Zero
*python()
Enter the Number:-33
num1 is Odd

Ques10. Write a program that creates a new list from existing list using slicing...
INPUT

list1=[1,2,3,4,5]
print("list1 is:",list1)

list2=list1[:]
print("list2 is:",list2)
OUTPUT

list1 is: [1, 2, 3, 4, 5]


list2 is: [1, 2, 3, 4, 5]

Ques11.Write a program to convert a string into list and display all the elements

using transversal..
INPUT

list1=list(str(input("Enter a String:")))
print(list1)

for i in list1:
print(i)

OUTPUT
Enter a String:COMPUTER

['C', 'O', 'M', 'P', 'U', 'T', 'E', 'R']


C
O
M

P
T
E

R
Ques12.Write a program to to check a given element is present in list or not...

INPUT
list1=list(str(input("Enter a String:")))

print(list1)
print('O'in list1)

print('S'in list1)
print(1 in list1)

print('C' in list1)
OUTPUT

Enter a String:COMPUTER
['C', 'O', 'M', 'P', 'U', 'T', 'E', 'R']
True
False
False

True

Ques13. Write a program to inputs principal rate and time and calculte simple
interest and amount..
INPUT
principal=float(input("Enter Principal:"))

rate=float(input("Enter rate:"))
time=5
Simple_interest=principal*rate*time/100

Amount=principal+Simple_interest
print("Simple_interest=Rs.",Simple_interest)

print("Amount=Rs.",Amount)
OUTPUT

Enter Principal:65
Enter rate:4

Simple_interest=Rs. 13.0
Amount=Rs. 78.0

Ques14.Write a program which convert temperature from Fahrenheit to


Celcius..

INPUT
cel=float(input("Enter temperature in Celcius:"))

print("Temperature in Celcius=",cel)
f=cel*9/5+32

print("Temperature in fahrenheit=", f)
OUTPUT

Enter temperature in Celcius:45


Temperature in Celcius= 45.0
Temperature in fahrenheit= 113.0

Ques15.Display sum of 1-x+x**2-x**3+x**4 -.....+x**n..

INPUT
#Display sum of 1-x+x**2-x**3+...+x**n

x=float(input("Enter base number:"))


n=int(input("Enter power number:"))

sum=1
for i in range(1,n+1):
if i%2==0:

sum=sum+x**i
else:

sum=sum-x**i
print("Sum of the series is:",sum)

OUTPUT
Enter base number:5

Enter power number:4


Sum of the series is: 521.0

Ques16.Write a program to print table of 6 ..


INPUT

#Python program to print table of 6


num=6
for i in range(1,11):
print(num,'X',i,'=',num*i)

OUTPUT
6X1=6
6 X 2 = 12

6 X 3 = 18
6 X 4 = 24

6 X 5 = 30
6 X 6 = 36

6 X 7 = 42
6 X 8 = 48

6 X 9 = 54
6 X 10 = 60

Ques17.Write a program to input two string and print concatenation of both..


INPUT

#Concatination of strings
x="COMPUTER"

y="PYTHON"
print(x+y)

print("SCHOOL"+"BUS")
s="LAP"+"TOP"

print(s)
OUTPUT
COMPUTERPYTHON
SCHOOLBUS

LAPTOP

Ques18.Write a program to find factorial of given number...

INPUT
num=int(input("Enter non negative no to take factorial of:"))

fact=1
for i in range(num):
fact=fact*(i+1)

print('Factorial of ',num,'=',fact)
OUTPUT

Enter non negative no to take factorial of:6


Factorial of 6 = 720

Ques19.Write a program to print Fibonacci series...


INPUT
num=int(input("Enter the any Number:"))
n1,n2=0,1

sum=0
if num<=0:

print('Please enter number greater than 0')


else:
for i in range(0,num):
print(sum,end="")
n1=n2

n2=sum
sum=n1+n2
OUTPUT

Enter the any Number:14


01123581321345589144233

Ques20. Display sum of x+x/2+x/3+x/4+...+x/n .


INPUT

x=int(input("Enter the value of x:"))


n=int(input("Enter the value of n:"))

summ=0
for i in range(1,n+1):

summ+=x/i
print("The sum is:",summ)

OUTPUT
Enter the value of x:10

Enter the value of n:5


The sum is: 22.833333333333332

Ques21. Write a program to print cube of number from 1 to 15..


INPUT
for i in range(1,16):
print("Cube of",i,end='')
print(" is",i**3)

OUTPUT
Cube of 1 is 1
Cube of 2 is 8

Cube of 3 is 27
Cube of 4 is 64

Cube of 5 is 125
Cube of 6 is 216

Cube of 7 is 343
Cube of 8 is 512

Cube of 9 is 729
Cube of 10 is 1000

Cube of 11 is 1331
Cube of 12 is 1728

Cube of 13 is 2197
Cube of 14 is 2744
Cube of 15 is 3375

Ques22.Write a program to take side of a triangle and print its area using

heron’s formula ......


INPUT

a=int(input("Enter the first side of a triangle:"))


b=int(input("Enter the second side of a triangle:"))
c=int(input("Enter the third side of a triangle:"))
s=a+b+c/2

A=(s*(s-a)*(s-b)*(s-c))**0.5
print("Area of a traingle =",A)
OUTPUT

Enter the first side of a triangle:2


Enter the second side of a triangle:3

Enter the third side of a triangle:4


Area of a traingle = 20.493901531919196

Ques23.Write a program to display sum of three numbers will be user...


INPUT

num1=int(input("Enter the first number:"))


num2=int(input("Enter the second number:"))

num3=int(input("Enter the third number:"))


Sum=num1+num2+num3

print("Three numbers are :",num1,num2,num3)


print("Sum is :",Sum)

OUTPUT
Enter
the first number:36
Enter the second number:64

Enter the third number:21


Three numbers are : 36 64 21
Sum is : 121

Ques24. Write a program that input string from user and counts the
number of vowels,consonants,digits,upper and lowercase letter..
INPUT

str=input("Enter the string :")


vowels=0

consonants=0
uppercase=0

lowercase=0
for i in range(0,len(str)):

if(str[i].isupper()):
uppercase=uppercase+1

elif((str[i].islower())):
lowercase=lowercase+1

str=str.lower()
for i in range(0,len(str)):
if ((str[i]=='a'or str[i]=='e'or str[i]=='i'or str[i]=='o'or str[i]=='u')):
vowels=vowels+1
else:

consonants=consonants+1
print("Vowels:",vowels);

print("Consonants:",consonants);
print("Uppercase:",uppercase);
print("Lowercase:",lowercase);
OUTPUT

Enter the string :CorPoRatIons


Vowels: 5
Consonants: 7

Uppercase: 4
Lowercase: 8

Ques25. Write a program that except a string from user whether it is


palindrome or not ...

INPUT
str=input("Enter the String :")

s=(str[::-1])
if str==s:

print("It is palindrome")
else:

print("It is not palindrome")


OUTPUT

*Enter the String :madam


It is palindrome

*Enter the String :Corporation


It is not palindrome

QUES26.Write a program to print the occurance of a given character


in numbers in a string ...
INPUT

str=input("Enter the string:")


char=input("Enter the character:")
count=0

for i in str:
if char==i:

count=count+1
print("Number of occurance of character is:",count)

OUTPUT
Enter the string : Corporation

Enter the character : o


Number of occurance of character is: 3

QUES27. Write a program that count and display even and odd
number...

INPUT
num=int(input("Enter any Number:"))

if num%2==0:
print("Number is Even")

else:
print("Number is odd")

OUTPUT
*Enter any Number:887
Number is odd

* Enter any Number:448


Number is Even

QUES28. Write a program that searches a given number is a list using


linear..

INPUT
List=[1,2,3,4,5,6]
Search=int(input("Enter a search number:"))

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


if Search==List[i]:

print(str(Search)+" Found at position "+str(i))


else:

print("Not found")
OUTPUT

*Enter a search number:6


6 Found at position 5

* Enter a search number:7


Not found

Ques29. Write a program to find minimum , maximum , sum and


average of all the elements of tuple...
INPUT

t=(10,20,30,40,50)

print(t)
print("Maximum of t :",max(t))

print("Minimum of t :",min(t))
print("Sum of t :",sum(t))

s=10+20+30+40+50/5
print("Average of t:",s)
OUTPUT

(10, 20, 30, 40, 50)


Maximum of t : 50

Minimum of t : 10
Sum of t : 150

Average of t: 110.0

Ques30.Write a program to perform following operations on tuple –

concatenation , transversal , membership , membership , slicing....


1)CONCATINATION

INPUT
t1=(10,20)

t2=(30,'Ram')
print("Concatination :",t1+t2)

OUTPUT
Concatination : (10, 20, 30, 'Ram')
2) REPETITION
INPUT
t1=(10,20)
print("Repetition:",t1*3)

OUTPUT
Repetition: (10, 20, 10, 20, 10, 20)

3)MEMBERSHIP
INPUT

t1=(10,20)
print(10 in t1)

print(16 not in t1)


print(15 in t1)

OUTPUT
True

True
False
4)INDEXING
INPUT
t1=(10,20,30,40,50)

print(t1[3])
print(t1[0])

print(t1[-1])
OUTPUT
40
10
50
5) SLICING
INPUT

t1=(10,20,30,40,50)
print(t1[0:2:1])
print(t1[::-1])
print(t1[0:4:2])

print(t1[0:3:1])
OUTPUT

(10, 20)
(50, 40, 30, 20, 10)

(10, 30)
(10, 20, 30)

QUES31. Write a program whether a key value pair is present in a


dictionary or not ....
INPUT
d={'S':'Summer','W':'Winter','A':'Autumn','R':'Rainy'}

my_dict=input("Enter the key you want to check:")


if my_dict in d:

print('The key is present')


else:
print('The key is not present')
OUTPUT

*Enter the key you want to check : W


The key is present
* Enter the key you want to check:Summer

The key is not present

QUES32. Create a dictionary with roll number , name and marks of n


student in class. Display the name of students who have marks greater
than 75...

INPUT
no_of_std=int(input("Enter number of students :"))

result={}
for i in range(no_of_std):

print("Enter the details of student no.",i+1)


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

std_name=input("Student Name:")
marks=int(input("Marks:"))

result[roll_no]=[std_name,marks]
print(result)

for student in result:


if result[student][1]>75:

print("Students who get more than 75 marks is/are:",(result[student][0]))


OUTPUT
Enter number of students :5
Enter the details of student no. 1
Roll Roll no :01
Student Name:John
Marks:78

Enter the details of student no. 2


Roll no :02

Student Name:Eva
Marks:89

Enter the details of student no. 3


Roll no :03

Student Name:Olaf
Marks:56

Enter the details of student no. 4


Roll no :04

Student Name:Harry
Marks:90
Enter the details of student no. 5
Roll no :05
Student Name:Maria

Marks:55
{1: ['John', 78], 2: ['Eva', 89], 3: ['Olaf', 56], 4: ['Harry', 90], 5: ['Maria', 55]}

Students who get more than 75 marks is/are: John


Students who get more than 75 marks is/are: Eva
Students who get more than 75 marks is/are: Harry

QUES33. Write a program that update dictionary ...

INPUT
d1={1:10,2:20,3:30,4:40,5:50}

d2={6:60,7:70,8:80,9:90,10:100}
d1.update(d2)

print(d1)
print(d2)
d2.update(d1)

print(d2)
print(d1)

OUTPUT
{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60, 7: 70, 8: 80, 9: 90, 10: 100}

{6: 60, 7: 70, 8: 80, 9: 90, 10: 100}


{6: 60, 7: 70, 8: 80, 9: 90, 10: 100, 1: 10, 2: 20, 3: 30, 4: 40, 5: 50}

{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60, 7: 70, 8: 80, 9: 90, 10: 100}

Ques34. Write a program nth term of Fibonacci series...

INPUT
n=int(input("Enter the length of fibonacci sequence:"))

n1=0
n2=1

count=2
if n<0:

print("Enter only positive values")

elif n==1:
print(n1)

else:
print(n1)

print(n2)
while count<n:

n3=n1+n2
print(n3)

count+=1
n1=n2
n2=n3

OUTPUT
Enter the length of fibonacci sequence:8

0
1

1
2

3
5

8
13

QUES35. Write a program to implement arithmetic, relational, short

hand and concatenation...

1)ARITHMETIC OPERATION

INPUT
print("18+5 =",18+5) #addition

print("15-3 =",15-3) #subtraction


print("16*2 =",16*2) #multiplication

print("47/5 =",47/5) #division


print("47//5 =",47//5) #Integer Division

print("27%5 =",27%5) #Modulus


print("3**3 =",3**3) #Exponentiation
print("-2**4 =",-2**4) #Exponentiation

OUTPUT

18+5 = 23
15-3 = 12

16*2 = 32
47/5 = 9.4

47//5 = 9
27%5 = 2

3**3 = 27
-2**4 = -16
2)CONCATINATIONAL OPERATION
INPUT

print("Hello"+"Python")
print("'How'+'are'+'you?':",'How'+'are'+'you?')
print("Python*3 :",'Python'*3)

OUTPUT

HelloPython
'How'+'are'+'you?': Howareyou?
Python*3 : PythonPythonPython

3)Relational Operation
INPUT

print("41<50 :",41<50) #less than


print("41>50 :",41>50) #greater then

print("41<=50 :",41<=50) #less than or equal to


print("41>=50 :",41>=51) #greater than or equal to

print("41==41 :",41==41) #equal to


print("41!=50 :",41!=50) #not equal to
OUTPUT
41<50 : True

41>50 : False
41<=50 : True

41>=50 : False
41==41 : True
41!=50 : True
4)SHORTHAND OPERATIONS

INPUT
a=6
a+=5 #addition
print(a)
a-=5 #subtraction

print(a)
a*=3 #multiplication

print(a)
a/=2 #division

print(a)
a%=2 #modulus

print(a)
a**=2 #exponention

print(a)
a//=2 #integeral division
print(a)
OUTPUT
11

6
18

9.0
1.0
1.0
0.0

You might also like