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

Computer Lab Practtical 1.ipynb - Colaboratory

The document contains Python code snippets that demonstrate various programming concepts like: 1) Printing output, accepting user input, and performing arithmetic, logical, and comparison operations. 2) Writing programs to calculate things like employee salary, check if a number is even/odd, find greatest among three numbers. 3) Using loops and conditional statements like if-else. 4) Converting temperatures between Celsius and Fahrenheit scales. 5) Computing a number raised to a power.

Uploaded by

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

Computer Lab Practtical 1.ipynb - Colaboratory

The document contains Python code snippets that demonstrate various programming concepts like: 1) Printing output, accepting user input, and performing arithmetic, logical, and comparison operations. 2) Writing programs to calculate things like employee salary, check if a number is even/odd, find greatest among three numbers. 3) Using loops and conditional statements like if-else. 4) Converting temperatures between Celsius and Fahrenheit scales. 5) Computing a number raised to a power.

Uploaded by

yash A.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1/31/23, 6:27 PM Computer Lab Practical 1.

ipynb - Colaboratory

my first program

print("Welcome to World of programming!!!")

Welcome to World of programming!!!

Write a program to print your biodata

print("Name \t:\t Ms Niti Arora")

Name : Ms Niti Arora

wap to accept a number and find it's 5 multiples

a=int(input("enter the number"))
b=a*2
c=a*3
d=a*4
e=a*5
f=a*6
print(b)
print(c)
print(d)
print(e)
print(f)

enter the number10


20
30
40
50
60

wap to accept name and basic salary of an employee. calculate and display??

HRA              32% of basic salary
DA               45% of basic salary
PF               12% of basic salary
GROSS            basic + HRA + DA
NET SALARY       GROSS - PF

N=input("Enter name:")
BS=int(input("Enter basic salary:"))
HRA=BS*.32
DA=BS*.45
PF=BS*.12
GROSS=BS+HRA+DA
NS=GROSS-PF
print("Name\t:\t",N)
print("BS\t:\t",BS)
print("HRA\t:\t",HRA)
print("DA\t:\t",DA)
print("PF\t:\t",PF)
print("GROSS\t:\t",GROSS)
print("NS\t:\t",NS)

Enter name:20
Enter basic salary:45000
Name : 20
BS : 45000
HRA : 14400.0
DA : 20250.0
PF : 5400.0
GROSS : 79650.0
NS : 74250.0

a=int(input("Enter your Na"))
if a>100: 
  print("3 digits number")

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 1/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
else : 
  print("less than 3 digit number")
Enter your Na45
less than 3 digit number

WAP to accept the number and find if even or odd

a=int(input("Enter Your Number"))
if a%2==0:
  print("The Number Is Even")
else:
  print("The Number Is Odd")

Enter Your Number45


The Number Is Odd

WAP to accept the number and check if divisible by 3

a=int(input("Enter Your Number"))
if a%3==0:
  print("The Number is divisible by 3")
else:
  print("The Number is not divisible by 3")

Enter Your Number521


The Number is not divisible by 3

WAP to accept the marks in a subject and name and display his/her Grades

a=input("Enter Your Name")
b=int(input("Enter Your Marks"))
if  b>=90:
  print("Grades = A+ : PASS")
elif 80<=b<90:
  print("Grades = A  : PASS")
elif 70<=b<80:
  print("Grades = B  : PASS")
elif 60<=b<70:
  print("Grades = C : PASS")
elif 50<=b<60:
  print("Grades = D : JUST PASS")
elif 30<=b<50:
  print("Grades = E : FAIL")

Enter Your NameArjit Singh


Enter Your Marks98
Grades = A+ : PASS

WAP to accept a year and determine whether it is a leap year or not

year=int(input("Enter Year : "))
if year %100==0 and year %400==0:
  print("Year : Is A Leap Century Leap Year ")
elif year %100!=0 and year %4==0:
  print("Year : It is A Leap Year")
else:
  print("Year : Is Not A Leap Year")

Enter Year : 2007


Year : Is Not A Leap Year

WAP to accept the number n and print:


a. natural no. from 1 to n
b. natural no. from n to 1
c. even no. from 2 to 2n
d. even no. from 2n to 2
e. odd no. from 2*n-1 to 1

a=int(input("Enter Number Here : "))
b=(a+1)

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 2/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
for c in range (1,b):
  print(c)
Enter Number Here : 34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

a=int(input("Enter Your Number : "))
for c in range (a,0,-1):
    print(c)

Enter Your Number : 06


6
5
4
3
2
1

a=int(input("Enter Your Number : "))
b=2*a+1
for c in range(2,b,2):
  print(c)

Enter Your Number : 10


2
4
6
8
10
12
14
16
18
20

a=int(input("Enter Your Number : "))
for c in range (2,2*a+1,2):
  print(c, end=',')

Enter Your Number : 29


2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,

a=int(input("Enter Your Number : "))
for c in range (1,2*a-1,2):
  print(c, end=',')

Enter Your Number : 39


1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 3/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
a=int(input("Enter Your Number : "))
for c in range (2,2*a,2):
  print(c, end=',')

Enter Your Number : 36


2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,

a=int(input("Enter Your Number : "))
for c in range (2,2*a-1,1):
   print (c, end=',')

Enter Your Number : 23


2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,

x=int(input("Enter Your Number : "))
s=0
for x in range(1,11):
  s+=x
print('sum=',s)

Enter Your Number : 90


sum= 55

a=int(input("Enter Your Number : "))
s=0
for a in range(1,a+1):
    s+=a
print('sum=',s)

Enter Your Number : 346


sum= 60031

n=int(input("Enter Your Number : "))
for n in range (1,11):
  print(n,"*",x,"=",n*x)

Enter Your Number : 43256


1 * 10 = 10
2 * 10 = 20
3 * 10 = 30
4 * 10 = 40
5 * 10 = 50
6 * 10 = 60
7 * 10 = 70
8 * 10 = 80
9 * 10 = 90
10 * 10 = 100

WAP to accept 3 numbers and find the greatest among them.

a=int(input("Enter Your Number : "))
b=int(input("Enter Second Number : "))
c=int(input("Enter Third Number : "))
if a>b and a>c:
  print("a is the Greatest Number")
if a<b and b>c:
  print("b is the Greatest Number")
if a<c and b<c:
  print("c is the Greatest Number")

WAP to accept the number and check if divisible by 3 and 5 or either.

a=int(input("Enter Your Number : "))
if a/3:
  print("a is divisible by 3")
if a/5:
  print("a is divisible by 5")
else:
  print("a is not divisible by 3 nor 5")

WAP to accept the number and check if it is positive even number or negative even number, positive odd or negative od or zero.

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 4/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
a=int(input("Enter Your Number : "))
if a%2==0 and a>0:
  print("The Number Is Positive Even")
else:
  print("The Number Is Positive Odd")

a=int(input("Enter Your Number : "))
if a%-2==0 and a<0:
  print("The Number Is Negative Even")
else:
  print("The Number Is Negative Odd")

WAP to accept 2 numbers and operator and perform arithmetic operations.

a=int(input("Enter Your First Number : "))
b=int(input("Enter Your Second Number : "))
operand=input("Enter Your Operator : ")

if operand =='+':
  print(a+b)
if operand =='-':
  print(a-b)
if operand =='*':
  print(a*b)
if operand =='/':
  print(a/b)

WAP to accept two numbers and swap them.

a=int(input("Enter your First Number : "))
b=int(input("Enter Your Second Number : "))

a , b = b , a
print(a,b)

WAP a programme that takes the name and age of the user as input and display a message whether the user is eligible to apply for driving
lisence or not.

a=input("Enter User's Name : ")
b=int(input("Enter User's Age : "))

if b>18:
  print("User Is Eligible For Driving License")
if b<18:
  print("User Is NOT Eligible For Driving License")

WAP to accept temperature in degree F and convert the temperature in degree C.

celsius_1 = float(input("Temperature value in degree Celsius: " ))  
  
# For Converting the temperature to degree Fahrenheit by using the above  
# given formula  
Fahrenheit_1 = (celsius_1 * 1.8) + 32  
    
# print the result  
print('The %.2f degree Celsius is equal to: %.2f Fahrenheit'  
      %(celsius_1, Fahrenheit_1))  
  
print("----OR----")  
celsius_2 = float (input("Temperature value in degree Celsius: " ))  
Fahrenheit_2 = (celsius_2 * 9/5) + 32  
    
# print the result  
print ('The %.2f degree Celsius is equal to: %.2f Fahrenheit'  
      %(celsius_2, Fahrenheit_2))

To Compute X^n for a given to integer X and n.

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 5/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory

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

n=int(input("Enter exponent:"))

z=x**n

print(z)

WAP to display natural number from 1 to 50

for a in range(1,51):
  print(a,end=",")

WAP to display even number from 2 to 50

for b in range(2,51):
  print(b,end=",")

WAP to display odd number from 1 to 50

for c in range(1,50):
  print(c,end=",")

WAP to accept the maximum number value and print natural number from 1 to n

n=int(input("Enter Your Number : "))
for a in range(2,n+2,2):
  print(a,end=",")

even numbers from 2 to n

n=int(input("Enter Your Number : "))
for a in range(2,n+2,2):
  print(a,end=",")

wap to display odd numbers from 1 to n

n=int(input("ENTER YOUR NUMBER : "))
for b in range(1,n+2,2):
  print(b,end=",")

Make a graph on the following

import matplotlib.pyplot as M
import numpy as N
import pandas as P

X=["Ajay","Raj","Deepak","Sumit"]
Y=[75,90,45,30]

print(X)
print(Y)

M.plot(X,Y)

import matplotlib.pyplot as M
import numpy as N
import pandas as P

X=["Ajay","Raj","Deepak","Sumit"]
Y=[75,90,45,30]

print(X)

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 6/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
print(Y)

M.bar(X,Y)

import matplotlib.pyplot as plt
import numpy as np

x = np.random.normal(170, 10, 250)

plt.hist(x)
plt.show() 

import matplotlib.pyplot as plt
import numpy as np

x=["Ajay","Raj","Deepak","Sumit"]
y = np.array([50, 50, 25, 25])

e=[0.1,0.1,0.1,0.1]
plt.pie(y,labels=x,explode=e)

plt.show() 

import matplotlib.pyplot as plt
import numpy as np

X=["Arjit","Vanshika","Ruchit","Ansh"]
Y=[75,90,45,30]

print(X)
print(Y)

plt.plot(X,Y, marker="*", ms=20, mfc='r')

import matplotlib.pyplot as M
import numpy as N
import pandas as P

X=["Arjit","Vanshika","Ruchit","Ansh"]
Y=[100,90,45,30]
c=["yellow","red","green","pink"]

print(X)
print(Y)

M.bar(X,Y ,color=c)

print("Enter Five Numbers Below")
num1=float(input("Enter First No : "))
num2=float(input("Enter Second No : "))
num3=float(input("Enter Third No : "))
num4=float(input("Enter forth No : "))
num5=float(input("Enter Fifth No : "))
divisor=float(input("Enter divisor Number : "))
count=0
print("Multiples of",divisor,"are : ")
remainder=num1%divisor
if remainder==0:
   print(num1,sep="")
   count+=1
remainder=num2%divisor
if remainder==0:
   print(num2,sep="")
   count+=1
remainder=num3%divisor
if remainder==0:
   print(num3,sep="")
   count+=1
remainder=num4%divisor
if remainder==0:
  print(num4,sep="")
  count+=1

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 7/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
remainder=num5%divisor
if remainder==0:
  print(num5,sep="")
  count+=1
print()
print(count,"multiples of",divisor,"found")

x=int(input("Enter The Value of X : "))
n=int(input("Enter The Value of N : "))
S=x
sign=+1
for a in range(2,n+1):
  f=1
  for i in range(1,a+1):
    f*=1
  term=((x**a)*sign)/f
  S+=term
  sign*=-1
print("sum of first",n,"terms :",S)

Enter The Value of X : 3


Enter The Value of N : 5
sum of first 5 terms : -177.0

WAP to accept a list of n numbers and find their sum and average

Wap to accept a list and find maximum and minimum

WAP to accept a list of n names and count names that starts with a vowel

WAP to accept a list of n names and display names tha ends with a vowel

WAP to accept a list of n numbers and count numbers of even and odd in the list

n=int(input("Enter Value of n : "))
L=[]
for a in range(n):
  a=int(input("Enter Data : "))
  L.append(a)
counte=0
counto=0
for a in L:
  if a%2==0:
    counte+=1
  else:
    counto+=1
print("Number is Even",counte)
print("Number is Odd",counto)

Enter Value of n : 6
Enter Data : 12
Enter Data : 13
Enter Data : 45
Enter Data : 67
Enter Data : 22
Enter Data : 26
Number is Even 3
Number is Odd 3

n=int(input("Enter Value of n : "))
L=[]
for a in range(n):
  a=input("Enter Data : ")
  L.append(a)
for a in L:
  if a[-1] in'aeiouAEIOU':
   print(a)

Enter Value of n : 3
Enter Data : arjit
Enter Data : bhuwan

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 8/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
Enter Data : aditya
aditya

n=int(input("Enter Value of n : "))
L=[]
for a in range(n):
  a=int(input("Enter Data : "))
  L.append(a)
s=0
for a in L:
  s+=a
print("sum=",s)

Enter Value of n : 6
Enter Data : 34
Enter Data : 35
Enter Data : 36
Enter Data : 37
Enter Data : 38
Enter Data : 39
sum= 219

n=int(input("Enter Value of n : "))
L=[]
for c in range(n):
  a=int(input("Enter Data : "))
  L.append(a)
  Max=L[0]
  for a in L:
     if a>Max:
      Max=a
print("Maximum",Max)

Enter Value of n : 6
Enter Data : 34
Enter Data : 35
Enter Data : 36
Enter Data : 37
Enter Data : 38
Enter Data : 39
Maximum 39

n=int(input("Enter The Value of n : "))
L=[]
for a in range(n):
  a=int(input("Enter Data : "))
  L.append(a)
s=0
for a in L:
  s+=a
print("Average=",s/n)

Enter The Value of n : 3


Enter Data : 10
Enter Data : 11
Enter Data : 12
Average= 11.0

n=int(input("Enter Value of n : "))
L=[]
for a in range(n):
  N=input("Enter Name : ")
  L.append(N)
for a in L:
  if a[0] in 'aeiouAEIOU':
    print(a)

Enter Value of n : 3
Enter Name : Maloy
Enter Name : Arjit
Enter Name : Ansh
Arjit
Ansh

L1=eval(input("Enter List 1 : "))
L2=eval(input("Enter List 2 : "))

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 9/14
1/31/23, 6:27 PM Computer Lab Practical 1.ipynb - Colaboratory
if L1>L2:
  print(L1)
elif L2>L1:
  print(L2)
else:
  print("Equal")
Enter List 1 : ["ajay","amit"]
Enter List 2 : ["Amit","Ajay"]
['ajay', 'amit']

WAP to accept n numbers and find 3 largest among them (WITHOUT ANY SORT)

n=int(input("Enter Value of n : "))
L=[]
for x in range(n):
  a=int(input("Enter Data : "))
  L.append(a)
Max=L[0]
for x in L:
  if x>Max:
    Max=x
print("Max No.=",Max)

Enter Value of n : 5
Enter Data : 456
Enter Data : 789
Enter Data : 234
Enter Data : 666
Enter Data : 111
Enter Data : 4567
Enter Data : 678
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-17-6bc0e591aea3> in <module>
6 L=[]
7 for a in range(n+1):
----> 8 a=int(input("Enter Data : "))
9 L.append(a)
10 Max=L[0]

1 frames
/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py in
_input_request(self, prompt, ident, parent, password)
902 except KeyboardInterrupt:
903 # re-raise KeyboardInterrupt, to truncate traceback
--> 904 raise KeyboardInterrupt("Interrupted by user") from None
905 except Exception as e:
906 self.log.warning("Invalid Message:", exc_info=True)

KeyboardInterrupt: Interrupted by user

SEARCH STACK OVERFLOW

n=int(input("Enter Value of n : "))
L=[]
L1=[]
for x in range(n):
    i=int(input("Enter Value : "))
    L.append(i)
L1=[]  
for x in range(3):
  max=0
  for a in L:
   if a>max and a not in L1:
    max=a
  L1.append(max)
print("max no.=",L1)

Enter Value of n : 5
Enter Value : 45
Enter Value : 67
Enter Value : 12
Enter Value : 89
Enter Value : 39
max no.= [89, 67, 45]

https://colab.research.google.com/drive/1XK3gprSuaLoPn-DhxU0z-HUUPlyCTCsl#printMode=true 10/14

You might also like