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

C.S practical file (1)

The document outlines various programming tasks and concepts related to computer architecture, memory types, algorithms, and flowcharts. It includes a series of Python programs demonstrating basic operations, mathematical calculations, string manipulations, list operations, and dictionary handling. Additionally, it provides definitions and comparisons of computer architecture generations and memory types.

Uploaded by

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

C.S practical file (1)

The document outlines various programming tasks and concepts related to computer architecture, memory types, algorithms, and flowcharts. It includes a series of Python programs demonstrating basic operations, mathematical calculations, string manipulations, list operations, and dictionary handling. Additionally, it provides definitions and comparisons of computer architecture generations and memory types.

Uploaded by

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

S.

NO Topic DATE PAGE REMARKS


NO.
1.
Computer Architecture and computer
Generations.
2. Memory of computer and its type difference.
3 Algorithm and flowchart.
1.
Program for printing name, class and school
name.
1.
Program for sum of two numbers.

1.
Program for product of two numbers.

1.
Program for performing all mathematical
operations.
1.
Program for finding area of circle.

1.
Program for calculating simple interest.

1.
Program for finding whether the age of a user is
eligible for voting
1.
program to grade student marks

1.
a program to print the bonus of an employee

1.
a program to print the series of While Loop

1.
a program to print series 101 to 150 using For
Loop
1.
a program to print the table of 16 using For
Loop
16) a program to find the factorial of a number
17) a program to print a pattern using For Loop.

18) a program to find out whether the number given


by the uses is positive, negative or equal to zero.
19) a program to find whether a number is divisible
by 7 or not.
20) menu dribble code.
21) a program to accept string from user and display
index values as 4,7,-6,-4,99
22) a program to perform basic operations of string
i.e concatenation and replication.
23) a program to find whether the sub-string is
present or not
24) a program to append an element in a list.
25) a program to reverse the list
26) a program to find the sum of the list
27) a program to find the max of the list.
28) a program to create a dictionary and access the
elements in the same.
29) a python script to concatenate dictionaries and
create a new one.
30) a python program to add a key to a dictionary.

31) a Python program to check whether a key exists


in a dictionary or not.
32) a program to print the sum of all values in the
dictionaries.
Question 1. Define Computer Architecture and Differentiate between the 5 Generations of
Computer.
Computer architecture is the arrangement of the components that comprise a computer
system and the engine at the core of the processes that drive its functioning. It specifies the
machine interface for which programming languages and associated processors are
designed.
First Second Third Fourth Fifth
Aspect Generation Generation Generation Generation Generation
Time 1940s - early Late 1950s - Early 1960s - Mid 1970s - mid Mid 1990s -
Period 1950s early 1960s mid 1970s 1990s Present
AI, Parallel
Processing,
Main Vacuum Integrated Natural
Technology Tubes Transistors Circuits (ICs) Microprocessors Language
Smaller in
Huge in size, size, less Shrinking size,
expensive to expensive becoming Miniaturization, Further
Size and build and than first more increased miniaturization,
Cost maintain generation affordable affordability affordability
Further
Low Improved improved Advanced
processing processing processing Increased processing
Processing power, limited power and power and processing power,
Power capabilities capabilities capabilities power, efficiency efficiency
Question 2. Define Memory in Computer and Differentiate between the types of Memory in
Computer.
Memory refers to the electronic components used by computers to store data and
instructions that can be accessed quickly by the processor. It allows you to store and retrieve
information for various computing tasks. There are two main types of memory. They are
Primary and Secondary memory.
Aspect Primary Memory Secondary Memory
Directly accessible by
Accessibility CPU Indirectly accessible by CPU via I/O operations
Volatile (loses data when
Volatility power is turned off) Non-volatile (retains data even when powered off)
Faster access and data
Speed transfer rates Slower access and data transfer rates
Capacity Typically smaller capacity Typically larger capacity
Cost per Higher cost per unit of
unit storage Lower cost per unit of storage
Data is transient and
Persistence temporary Data is persistent and long-term
Stores actively running
Usage programs and data Stores data and programs not currently in use
Hard disk drives (HDDs), Solid-state drives (SSDs),
Examples RAM, Cache memory Magnetic tapes, Optical discs (CDs, DVDs)
Question 3.Write an algorithm and draw a flow chart for the following problem statements-
PROBLEM STATEMENT 1- Addition of two numbers
Step1. Start
Step2. Input first number (num1)
Step3. Input second number (num2)
Step4. Add num1 and num2, store the result in sum
Step5. Display sum
Step6. End
PROBLEM STATEMENT 2- Area of a circle
Step1. Start
Step 2. Input radius of the circle (radius)
Step 3. Calculate area using formula: area = π * radius^2
Step 4. Display area
Step 5. End
PROBLEM STATEMENT 3- Find the greatest of two numbers
Step 1. Start
Step 2. Input first number (num1)
Step 3. Input second number (num2)
Step 4. If num1 > num2
Step 4.1 Display num1 is the greatest
Else
Step 4.2 Display num2 is the greatest
Step 5. End
Question 4. Write a program to print your name, class and school in python shell.
SOURCE CODE
print(“Nandini Tanwar; XI B; Summer Fields School”)

OUTPUT

Question 5. Write a program to add two numbers and print the output in the shell.
SOURCE CODE
a = 17
b = 1179
c=a+b
print ("Sum of numbers", c)
OUTPUT

Question 6. Write a program to multiply two numbers and take the values from the user.
SOURCE CODE
a = int (input ("Enter a number "))
b = int (input ("Enter another number "))
c=a*b
print ("Product of the two numbers", c)
OUTPUT

Question 7. Write a program to perform all mathematical operations and take the values
from the user.
SOURCE CODE
a = int (input ("Enter number 1 "))
b = int (input ("Enter number 2"))
c=a+b
d=a-b
e=a*b
f=a/b
print ("Sum of the two numbers", c)
print ("Difference of the two numbers", d)
print ("Product of the two numbers", e)
print ("Quotient of the two numbers", f)
OUTPUT

Question 8. Write a program to find the area of a circle.


SOURCE CODE
pi = 3.14
r = float (input ("Enter the radius "))
area = pi * r*r
print ("Area of the circle", area)
OUTPUT
Question 9. Write a program to calculate Simple Interest. Take values of Principal Sum, Rate
of Interest and Time from the user.
SOURCE CODE
p = int (input ("Enter the principal amount "))
r = float (input ("Enter the R "))
t = int (input ("Enter the time period "))
si = (p*r*t)/100
print ("Simple interest", si)
OUTPUT
Question10. Write a program to find whether the age of the user is eligible for voting or not.
Take the value from the user.
SOURCE CODE
age = int (input ("Enter your age "))
if age < 18:
print ("You are not eligible to vote.")
else:
print ("You are eligible to vote.")
OUTPUT
Question 11. Write a program to grade student marks. Take the value from the user.
SOURCE CODE
marks = int(input("Enter your marks"))
if marks >= 90:
print(" A ")
elif marks >= 80:
print(" B ")
elif marks >= 70:
print(" C ")
elif marks >= 60:
print(" D ")
elif marks >= 50:
print(" E ")
else:
print("Grade: F")

OUTPUT

Question 12. Write a program to print the bonus of an employee. Take the value from the
user.
Source Code
Salary = int(input(“ Enter your Salary”))
Service = int(input(“ Enter your service year”))
bonus = 5/100*Salary
if Service>= 5:
print(“Net bonus”, bonus)
Gross_Salary = bonus + Salary
print(“ Gross Salary”, Gross_Salary)
OUTPUT
Question 13. Write a program to print the series of While Loop.
1. 20, 40, 60, 80, 100
SOURCE CODE
num = 20
while num <= 100:
print(num)
num += 20

OUTPUT
2. 1, 3, 5, 7
SOURCE CODE
num = 1
while num < 10:
print(num)
num += 2

OUTPUT
3. 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
SOURCE CODE
num = 10
while num >= 1:
print(num)
num = num - 1
OUTPUT
4. 117, 104, 91, 78, 65
SOURCE CODE
num = 117
while num> = 65:
print (num)
num = num - 13
OUTPUT
Question 14. Write a program to print series 101 to 150 using For Loop.
SOURCE CODE
for i in range (101, 151):
print(i)

OUTPUT
Question 15. Write a program to print the table of 16 using For Loop.
SOURCE CODE
a = 16
for i in range (1,11):
print(a, ‘x’ , i , ‘=’ , a*1)
OUTPUT
Question 16. Write a program to find the factorial of a number ( Take the value from the
user).
SOURCE CODE
num = int(input(“Enter a number”))
factorial = 1
if num<0:
print(“ Sorry no factorial for negative number”)
elif num == 0:
print(“ The factorial of 0 is 1”)
else:
for i in range(1,num+1):
factorial = factorial*i
print(“The factorial of”, num, “is”, factorial)
OUTPUT

Question 17. Write a program to print a pattern using For Loop.


SOURCE CODE
for j in range(0, 5):
for i in range(0, j +1):
print(i, end="")
print()
OUTPUT
*
**
***
****
*****

Question 18. Write a program to find out whether the number given by the uses is positive,
negative or equal to zero.
SOURCE CODE
n = int(input( “Enter a number”))
if n <0:
print(“ Number is negative”)
elif n ==0:
print(“ Number is equal to zero”)
else:
print(“ Number is positive”)
OUTPUT

Question 19.Write a program to find whether a number is divisible by 7 or not.


SOURCE CODE
n = int(input("Enter a number"))
if n%7 == 0:
print(" Number is divisible by 7")
else:
print(" Number is not divisible by 7")
OUTPUT
Question 20. Write a menu dribble code.
SOURCE CODE
print(" 1 CUBE FORMULA")
print(" 2 CUBOID FORMULA")
print(" 3 CYLINDER FORMULA")
a = float(input("Enter your choice"))
if a ==1:
print(" 1.C.S.A")
print("2. T.S.A")
print9("3. VOLUME")
n = float(input("Enter your choice"))
if n == 1:
print(" 4A")
elif n ==2:
print(" A*A ")
else:
print(" A*A*A ")
elif a ==2:
print(" 1.C.S.A")
print("2. T.S.A")
print9("3. VOLUME")
n = float(input("Enter your choice"))
if n == 1:
print(" 2(LB + BH+ HL)")
elif n ==2:
print(" 2H(L + B)")
else:
print(" L*B*H ")
else:
print(" 1.C.S.A")
print("2. T.S.A")
print("3. VOLUME")
n = float(input("Enter your choice"))
if n == 1:
print(" 2*PI*R*h")
elif n ==2:
print(" 2*pi*r(r+h)")
else:
print("pi*r*r*h")
OUTPUT

Question 21. Write a program to accept string from user and display index values as 4,7,-6,-
4,99
SOURCE CODE
string = input("Enter a name")
print(string[4])
string = input("Enter a name")
print(string[7])
string = input("Enter a name")
print(string[-6])
string = input("Enter a name")
print(string[-4])
string = input("Enter a name")
print(string[99])
OUTPUT

Question 22. Write a program to perform basic operations of string i.e concatenation and
replication.
1. Concatenation
SOURCE CODE
str1 = "Hi!"
str2 = "How are you?"
str3= str1 + str2
print(str3)
OUTPUT
2. Replication
str1 = "Hi!"
str2 = str1*2
print(str2)
OUTPUT
Question 23. Write a program to find whether the sub-string is present or not.
SOURCE CODE
str = "Hello! I'm Uzui Tengen. I'm God of festivals and God of flashiness."
res= str.find("for")
if res>0:
print("Present in string")
else:
print("Not present in string")
OUTPUT

Question 24. Write a program to append an element in a list.


SOURCE CODE
names = ["Nandini","Lavanya","Yashi"]
print("Current name list is", names)
new_name= input("Enter names")
names.append(new_name)
print("Updated name list is", names)
OUTPUT

Question 25. Write a program to reverse the list


SOURCE CODE
l1 = [15,7,9,1507,7090,1500]
L1.(num)
print(l1)
OUTPUT
Question 26. Write a program to find the sum of the list
SOURCE CODE
L1 = [15,7,9,1507,7090,1500]
result = sum(L1)
print("Sum of numbers", result)
OUTPUT
Question 27. Write a program to find the max of the list.
SOURCE CODE
L1 = [15,7,9,1507,7090,1500]
result = max(L1)
print("Max of numbers", result)
OUTPUT
Question 28. Write a program to create a dictionary and access the elements in the same.
SOURCE CODE
a = {'Lavanya':90/ 'Yashi':95,'Nandini':80}
print(a['Lavanya'])
OUTPUT
Question 29. Write a python script to concatenate dictionaries and create a new one.
SOURCE CODE
dic1 = {1:10,2:20}
dic2 = {3:30,4:40}
dic3 = {5:50,6:60}
dic4 = {}
for d in (dic1, dic2, dic3):
dic4.update(d)
print(dic4)
OUTPUT

Question 30. Write a python program to add a key to a dictionary.


SOURCE CODE
d = {"Name":"Ram","Age":23}
print(d)
d.update
({"City":"Delhi"})
print(d)
d["Gender"]='Male'
print(d)
OUTPUT

Question 31. Write a Python program to check whether a key exists in a dictionary or not.
SOURCE CODE
d = {"Name":"Ram","Age":23}
if "Name" in d:
print("Key is present in dictionary")
else:
print("Key is not present in dictionary")
if "City" in d:
print("Key is preset in dictionary")
else:
print("Key is not present in dictionary")
OUTPUT

Question 32. Write a program to print the sum of all values in the dictionaries.
SOURCE CODE
d = {1:23,2:45,3:-17,4:48}
print(sum(d.values()))
OUTPUT
PART 2
Question 1. To implement OR GATE and show a truth table with all combinations.
Truth Table
Cases Input A Input B Output W
Case 1 0 0

Case 2 0 1

Case 3 1 0

Case 4 1 1

Question 2. To implement AND GATE and show a truth table with all combinations.
Truth Table
Cases Input A Input B Output W
Case 1 0 0

Case 2 0 1

Case 3 1 0

Case 4 1 1

Question 3. To implement NOT GATE and show a truth table with all combinations.
Truth Table
Cases Input A Output W
Case 1 0

Case 2 1

Question 4. To implement XOR GATE and show a truth table with all combinations.
Truth Table
Cases Input A Input B Output W
Case 1 0 0

Case 2 0 1

Case 3 1 0

Case 4 1 1

Question 5. To implement NOR GATE and show a truth table with all combinations.
Truth Table
Cases Input A Input B Output W
Case 1 0 0

Case 2 0 1

Case 3 1 0

Case 4 1 1

Question 33. Write a program to find the area of a circle using math module.
SOURCE CODE
import math
a= int(input("Enter a radius"))
print("Area of the circle is",math.pi*a*a)

OUTPUT

Question 34. Write a square root using math module


SOURCE CODE
import math
print(math.sqrt(289))
OUTPUT

Question 35. Write a program to calculate the power of a number using math
module.
SOURCE CODE
import math
print(math.pow(64, 2))
OUTPUT
Question 36. Write a Python program to guess a number between 1 to 10
SOURCE CODE
import random
num = random.randint(1,10)
guess = None
while guess != num:
guess= input("Guess a number between 1 to 10")
guess = int(guess)
if guess ==num:
print("Congrats! you won!")
break
else:
print("nope, try again")

OUTPUT

You might also like