C.S practical file (1)
C.S practical file (1)
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.
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
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 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 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 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 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