Programme Number: 1 Input
Programme Number: 1 Input
Programme Number: 1 Input
INPUT
Num = int (input (“Enter an integer :”))
If num % 2 == 0:
Print (num, “is EVEN number.”)
Else:
Print (num, “is ODD number.”)
OUTPUT
Enter an integer: 8
8 is EVEN number.
Programme number: 2
INPUT
X=Y=Z=0
X = float (input (“enter first number :”))
Y = float (input (“enter second number :”))
z = float (input (“enter third number :”))
Max = x
If y > max:
Max = y
If z > max:
Max = z
Print (“Largest number is”, max)
OUTPUT
Enter first number: 7.235
Enter second number: 6.99
Enter third number: 7.533
Largest number is 7.533
Programme number: 3
INPUT
# Programe to print mersenne numbers
Print (“first 10 mersenne numbers are :”)
For an in range (1, 11):
Mersenne = 2 ** a – 1
Print (mersenne, end = ““)
Print ()
OUTPUT
First 10 mersenne number are: 1 3 7 15 31 63 127 255 511
1023
Programme number: 4
INPUT
# Programe to print mersenne prime numbers
For an in range (1, 21):
Mersenne = 2** a – 1
For b in range (2, mid):
If mersenne %b == 0:
Print (mersenne)
Break
Else:
Print (mersenne, “\prime”)
OUTPUT
(With first 10 mersenne numbers)
1 prime
3 prime
7 prime
15
31 prime
63 prime
127
255
511
1023
Programme number: 5
INPUT
For an in range (3, 10, 2):
For b in range (1, a, 2):
Print (b, end = ‘ ‘)
Print ( )
OUTPUT
1
13
135
1357
Programme number: 6
INPUT
N=1
For an in range (5):
Print (n)
n = n *10+1
OUTPUT
1
11
111
1111
11111
Programme number: 7
INPUT
For i in range (4):
for j in range (4, I, -1):
Print (j, end =” “)
Else:
Print ( )
OUTPUT
4321
432
42
4
Programme number: 8
INPUT
String1 = input (“enter a string :”)
Print (“the”, string1, in reverse order is :”)
Length = Len (string1)
For an in range (-1, (-length -1), -1):
Print (string1 [a])
OUTPUT
Enter a string: python
The python in reverse order is:
n
o
h
t
y
p
Programme number: 9
INPUT
String = ‘#’
Pattern = “ “ #empty string
For a in range (5):
Pattern += string
Print (pattern)
OUTPUT
#
##
###
####
#####
Programme number: 10
INPUT
1st = eval (input (“Enter list :”))
Length = Len (1st)
Min_ele = 1st [0]
Min_index = 0
For I in range (1, length-1):
If 1st [i] <min_ele:
Min_ele = 1st
Min_index = i
Print (“given list is: “, 1st)
Print (“the minimum element of the given list is :)
Print (Min_ele, “at index “, min index)
OUTPUT
Enter list: [2, 3, 4, -2, 6, -7, 8, 11, -9, 11]
Given list: [2, 3, 4, -2, 6, -7, 8, 11, -9, 11]
The minimum element of the given list is: -9 at index 8
Programme number: 11
INPUT
1st = eval (input (“Enter list :”))
Length = Len (1st)
Mean = sum = 0
For I in range (1, length-1):
Sum +=1st[i]
Mean = sum/length
Print (“given list is: “, 1st)
Print (“the mean of the given list is:” mean)
OUTPUT
Enter list: [7, 23, -11, 55, 13, 5, 20.05, -5.5,]
Given list is: [7, 23, -11, 55, 13, 5, 20.05, -5.5,]
The mean of the given list is: 15.36455467714
Programme number: 12
INPUT
1st = eval (input (“Enter list :”))
Length = Len (1st)
Element = int (input (“enter element to be searched for
:”))
For I in range (0, length-1):
If element == 1st [i]:
Print (element, “found at index”, 1)
Break
Else: # else of for loop
Print (element, “not found in given list”)
OUTPUT
Enter list: [2, 8, 9, 11, -55, -11, 22, 78, 67]
Enter element to be searched for: -11
-11 found at index 5
Programme number: 13
INPUT
1st = eval (input (“Enter list :”))
Length = Len (1st)
Element = int (input (“enter element :”))
Count = 0
For i in range (0, length-1):
If element == 1st[i]
Count += 1
If count == 0:
Print (element, “not found in given list”)
Else:
Print (element, “has frequency as”, count,” in
given list”)
OUTPUT
Enter list: [1, 1, 1, 2, 3, 4, 2, 2, 5, 5, 2, 2, 5]
Enter element: 2
2 has frequency as 6 in given list
Programme number: 14
INPUT
T = (“hello’, isn’t, ‘python’, ‘fun’, ‘?’)
Length = Len (T)
For a in range (length)
Print (‘at indexes’, a, ‘and’, (a – length),
‘element:’ T[a])
OUTPUT
At indexes 0 and -5 element: Hello
At indexes 1 and -4 element: Isn’t
At indexes 2 and -3 element: Python
At indexes 3 and -2 element: Fun
At indexes 4 and -1 element: ‘?’
Programme number: 15
INPUT
Employees = {‘John’: {‘age’: 25,’salary’:
20000},’Diya’: {‘age’: 35,’salary’: 50000}}
For key in employees:
Print (“employee”, key ‘:’)
Print (‘age:’ str (employee [key] [‘age’]))
Print (‘salary:’ str (employee [key] [‘salary’]))
OUTPUT
Employee john:
Age: 25
Salary: 20000
Employee Diya:
Age: 35
Salary: 50000
Programme number: 16
INPUT
N = int (input (“how many students?”))
Compwinner = { }
For an in range (n):
Key = (input (“name of the students?”)
Value =int (input (“name of the competitions won
:”)
Compwinner [key] = value
Print (“the dictionary now is :”)
Print (compwinners)
OUTPUT
How many student? 5
Name of the student: Rohan
Number of the competition won: 5
Name of the student: zeba
Number of the competition won: 3
Name of the student: Nihar
Number of the competition won: 3
Name of the student: Roshan
Number of the competition won: 1
Name of the student: James
Number of the competition won: 5
The dictionary now is:
{‘Nihar’:3, ‘Rohan’: 5, ‘Zeba’: 3, ‘Roshan’: 1,
‘James’: 5}
Programme number: 17
INPUT
# to input 3 numbers and print their sum
Num1 = int (input (“Enter number 1 :”))
Num2 = int (input (“Enter number 2 :”))
Num3 = int (input (“Enter number 3 :”))
Sum = num1 + num2 + num3
Print (“three numbers are: “, num1, num2, num3)
Print (“sum is:” sum)
OUTPUT
Enter number 1: 7
Enter number 2: 3
Enter number 3: 13
Three numbers are: 7 3 13
Sum is: 23
Programme number: 18
INPUT
A = int (input (“Enter any number :”))
B = int (input (“Enter any number :”))
C = a+b
Print (“sum =”, c)
OUTPUT
A = B = C = 10
A, B, C = 20, 30,
Programme number: 19
INPUT
# to input length and breadth of a rectangle and
calculate its area
Length = float int (input (“Enter length of a
rectangle :”))
Breadth = float int (input (“Enter breadth of a
rectangle :”))
Area = length*breadth
Print (“rectangle specifications”)
Print (“length =”, length, end = ‘ ’)
Print (“breadth =”, breadth, end = ‘ ’)
Print (“area =”, area)
OUTPUT
Enter length of a rectangle: 8.75
Enter breadth of a rectangle: 35.0
Rectangle specifications
Length = 8.75 breadth = 35.0
Area = 306.25
Programme number: 20
INPUT
For i in range (1, 4)
For j in range (1, i)
Print (*)
Print ( )
OUTPUT
1
12
123
1234