Professional Documents
Culture Documents
(CSE)
Session :- July-Dec-2021
Section -F
INDEX
19100BTCSES05384 NAYAN SHARMA
BTCS-407 PROGRAMMING WITH PYTHON
c) Implement python script to check the given year is leap year ornot.
c) Implement python script to accept line of text and find the number of
characters, number of vowels and number of blank spaces in it.
b) Write Python script to copy file contents from one file toanother.
Experiment – 1
Aim: Write a program for checking the given number is even or odd.
Write a program for displaying reversal of a number.
Code:
1:
O/P:
Enter a number: 43
43 is Odd
Enter a number: 18
18 is Even
2.
num = 1234
reversed_num = 0
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit num //= 10
O/P:
4321
Experiment - 2
Implement python script to check the given year is leap year or not.
Code:
O/P:
Enter first number: 1.5
Enter second number: 6.3
The sum of 1.5 and 6.3 is 7.8
2.
if x >= 18:
print("User is valid for voting:", x)
else:
print("User is not valid for voting:", x)
O/P:
Enter age of a user:45
User is valid for voting: 45
3.
# Python program to check if year is a leap year or not
year = 2000
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
O/P:
2000 is a leap year
Experiment – 3
Code:
1.
# Program to check if a string is palindrome or not
my_str = 'aIbohPhoBiA'
O/P:
2.
factorial = 1
O/P:
The factorial of 4 is 24
3.
num = 10
if num < 0:
print("Enter a positive number")
else:
sum = 0
# use while loop to iterate until zero
while(num > 0):
sum += num
num -= 1
print("The sum is", sum)
O/P:
The sum is 55
4.
O/P:
Experiment – 4
Aim: Finding the sum and average of given numbers using lists.
OUTPUT:
Output:
Experiment – 5
>>concatenation
>>Casemethods
>>count(str)
>>split()
>>replace()
>>len()
output:-
Output:
Experiment – 6
Experiment – 7
Code:
Output:
Output:
Experiment – 8
Output:
Output:
Experiment – 9
Output:
2 Write Python script to copy file contents from one file to another.
Output:
Experiment – 10
Code:
Output:
--------------------------------------------End----------------------------------------------------------------------