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

Practical File Computer Science-1

Uploaded by

Ruby Bull
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Practical File Computer Science-1

Uploaded by

Ruby Bull
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

DELHI PUBLIC SCHOOL

RANIPUR, HARIDWAR

Computer Science
Practical File
Session 2022-23
1. Write a program to print the table of a given number

n=3
for i in range(1,10):
print("3 x",i,"=", 3 * i)
2. Write a program that accepts three numbers from user and display the largest number

num1 = input("Enter first number:")


num2 = input("Enter second number:")
num3 = input("Enter third number:")
max = num1
if num1 < num2:
max = num2
if max < num3:
max = num3
print("Largest number is",num3)
3. Write a program to accept a number and display whether the given number is Palindrome or not.
n = input("Enter number:")
if list(n) == list(n)[::-1]:
print("Number is a palindrome")
else:
print("Number is not a palindrome")
4. Write a program to print the factorial of a number entered by the user
n = int(input("Enter a number: "))
factorial = 1
for i in range(1,n + 1):
factorial = factorial*i
print("The factorial of",n,"is",factorial)
5. Write a program to print the sum of digits of a number given by the user
n = input("Enter number:")
num = []
for i in n:
num.append(int(i))
sum = 0
for i in numbers:
sum += i
print("Sum is",sum)
6. Write a program to print the product of digits of a number given by the user
n = input("Enter number\n")
num = []
for i in n:
num.append(int(i))
product = 1
for i in numbers:
product *= i
print("Product is",product)
7. Write a program to check whether the entered number is 7 Armstrong Number or not
num = input("Enter number:")
numbers = []
for i in num:
numbers.append(int(i))
sum = 0
for i in numbers:
sum += i**len(numbers)
if sum == int(num):
print("Armstrong number")
else:
print("Not an Armstrong number")
8. Write a program to print Fibonacci Sequence upto nth term, accepted from user
terms = int(input("Enter number of terms: "))
n1, n2 = 0, 1
count = 0
if terms == 0:
print(0)
elif terms == 1:
print(n1)
else:
while count < terms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
9. Write a program to print the following star pyramid pattern using concept of nested loop.

a)

n=5
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end="")
print()
for i in range(1, n + 1):
for j in range(1, i + 1):
print(i, end='')
print()
n=5
for i in range(n, 0, -1):
num = i
for j in range(i, n+1):
print(num, end=' ')
print()
n=5
for i in range(n+1, 0, -1):
for j in range(i-1):
print(j+1, end=" ")
print()

10. Write a program to print the following pattern using concept of nested loop
n=5
for i in range(1, n+1):
for j in range(i):
print("*", end=" ")
print()
n=5
for i in range(n, 0, -1):
for j in range(i):
print("*", end="")
print()

n=5
for i in range(n):
for j in range(n-i-1):
print(" ", end="")
for k in range(i+1):
print("* ", end="")
print()

11.Write a program to print the following Alphabetical pattern using concept of nested loop.

n=5
for i in range(n):
for j in range(i+1):
print(chr(65+j), end=" ")
print()
rows = 5
for i in range(rows):
for j in range(i+1):
print(chr(65+i), end="")
print()
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
sum = 0
for i in range(n+1):
sum += x**i
print(sum)
13. Write a program to accept a character from the user and display whether it is a vowel or
consonant.
char = input("Enter a character: ")
if char in ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'):
print("Vowel")
else:
print("Consonant")
14. Write a program to print the sum of First n natural numbers, accept the value of n from
user.

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


sum = 0
for i in range(1, n+1):
sum += i
print("Sum of first", n, "natural numbers is", sum)
choice = input("Enter 1 for area of circle, 2 for area of rectangle, 3 for area of square:")
if int(choice) == 1:
rad = input("enter radius:")
print("area is", 3.14 * int(rad) * rad(int))
elif int(choice) == 2:
height = int(input("Enter height:"))
width = int(input("Enter width:"))
print("Area is", height * width)
elif int(choice) == 3:
side = int(input("Enter side:"))
print("Area is", side ** 2)
chem = int(input("enter marks in chemistry:"))
bio = int(input("Enter marks in bio:"))
maths = int(input("Enter marks in maths:"))
physics = int(input("Enter marks in physics:"))
history = int(input("Enter marks in history:"))
percentage = (chem + bio + maths + physics + history) / 5
print("Total marks are", chem + bio + maths + physics + history)
print("Perentage is ", percentage)
if percentage > 75:
print("Grade is A")
elif percentage >= 60 and percentage < 75:
print("Grade is B")
elif percentage >= 45 and percentage < 60:
print("Grade is C")
elif percentage >= 33 and percentage < 45:
print("Grade is D")
elif percentage < 33:
print("Reappear")
17. WAP to find the largest and smallest elements in the list of integers entered by the user
without using sort() function

a= []
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
a.append(int(input("Enter the element: ")))
b = a[0]
for i in a:
if i > b:
b=i
print("Maximum is",b)
for i in a:
if i < b:
b=i
print("Minimum is",b)
18. Input a list of numbers and swap elements at the even location with the elements at the
odd location.
list1 = [ ]
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
list1.append(int(input("Enter the element: ")))
for i in range(0,len(list1),2):
list1[i],list1[i+1]=list1[i+1],list1[i]
print(list1)
19. WAP that returns the largest even number in the list of integers. If there is no even
number in input, print “No even number”.
a= []
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
a.append(int(input("Enter the element: ")))
b = a[0]
c=0
for i in a:
if (i % 2) == 0:
if i > b:
b=i
c += 1
if c == 0:
print("No even number")
if b != a[0]:
print("Largest even number is",b)
20. WAP that prints the sum of the even indexed elements of L, minus the sum of the odd
indexed elements of L.
a = eval(input("Enter the list: "))
even_sum = 0
odd_sum = 0
for i in range(len(a)):
if i % 2 == 0:
even_sum += a[i]
else:
odd_sum += a[i]
print("Result is", even_sum - odd_sum)
21. WAP to print the alternate elements of a tuple T
a = eval(input("Enter the tuple: "))
print(a[::2])
22. WAP to print every 3rd element of a tuple T
a = eval(input("Enter the elements of the tuple: "))
print(a[::3])

23.Write a python program that inputs two tuples and creates a third that contains all
elements of the first followed by all elements of the second.
a = eval(input("Enter the elements of the first tuple: "))
b = eval(input("Enter the elements of the second tuple: "))
c=a+b
print(c)

24. Create a dictionary with the roll number, name and marks of n students in a class and
display the names of students who have scored marks above 75
n=int(input("Enter number of students: "))
d={}
for i in range(n):
roll_no=int(input("Enter roll no: "))
name=input("Enter name: ")
marks=int(input("Enter marks: "))
d[roll_no]=[name,marks]
print("Students with more than 75: ")
for k in d:
if(d[k][1]>75):
print(d[k][0])

25.Create a nested dictionary that stores the marks details along with student names and then
prints the output.

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


d={}
for i in range(n):
# roll_no=int(input("Enter roll no: "))
name=input("Enter name: ")
maths=int(input("Enter marks in maths: "))
physics = int(input("Enter marks in physics: "))
chem = int(input("Enter marks in chem: "))
d[name]={'maths':maths,'physics':physics, "chemistry":chem}
print(d)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy