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

Docs

The document contains 16 Python programs demonstrating basic concepts like arithmetic operations, area calculations, square roots, factorials, loops, conditional statements, functions on data types like tuples, lists and dictionaries. It accepts user input, performs calculations and prints outputs. Overall it covers fundamental Python programming techniques for numerical, logical and data processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Docs

The document contains 16 Python programs demonstrating basic concepts like arithmetic operations, area calculations, square roots, factorials, loops, conditional statements, functions on data types like tuples, lists and dictionaries. It accepts user input, performs calculations and prints outputs. Overall it covers fundamental Python programming techniques for numerical, logical and data processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.#Program to add/sub/mul/div no.

s
a = 6; b = 3;
c = a + b
print(c)
c = a - b
print(c)
c = a * b
print(c)
c = a / b
print(c)

Output:- 9
3
18
2.0
2.#Program to find area of square/rectangle/circle
l = 4;b =5;r = 7;
print("Area of rectangle = ",l * b)
print("Area of square = ",l * l)
print("Area of circle = ",3.14 * r * r)
Output:- Area of rectangle = 20
Area of square = 16
Area of circle = 153.86

3.#Program to find square root of a number


import math
a = 49;
print("square root of a number = ",math.sqrt(a))
Output:- square root of a number = 7.0

4. #Program to find power of a number


import math
a = 8;
print("Power of a number = ",math.pow(a,2))
Output:- Power of a number = 64.0
5. #Program to find cube of a number
import math
a = 3;
print("Cube of a number = ",math.pow(a,3))
Output:- Cube of a number = 27.0
6. #Program to swap two variables with/without 3rd var.
a = 3;b = 9;
print("Values before swapping: a=",a," b=",b)
c=a

Tejas Garad 211106068 Batch A


a=b
b=c
print("Values after swapping with 3rd variable: a=",a," b=",b)
a=a+b
b=a-b
a=a-b
print("Values after swapping without 3rd variable: a=",a,"
b=",b)
Output:- Values before swapping: a= 3 b= 9
Values after swapping with 3rd variable: a= 9 b= 3
Values after swapping without 3rd variable: a= 3 b= 9

7. #Program to find largest of two no.


a = 3;b = 9;
if(a>b):
print("a is larger than b")
else:
print("b is larger than a")
Output:- b is larger than a
8. #Program to find divisibility by 5
a = 67
if(a%5==0):
print("divisible by 5")
else:
print("not divisible by 5")
Output:- not divisible by 5

9. #Program to check if no is -ve,+ve or 0


a = -98
if(a>0):
print("number is positive")
elif(a<0):
print("number is negative")
else:
print("number is zero")
Output:- number is negative

10. #Program to print a calender


import calendar
yy = 2023
mm = 4
print(calendar.month(yy, mm))
Output:-
April 2023
Mo Tu We Th Fr Sa Su

Tejas Garad 211106068 Batch A


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

11. #Program to find factorial of a number


num = 5
factorial = 1
if 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:- The factorial of 5 is 120
12. #Program to find sum of first n +ve natural no.s
n = 4
sum = 0
for i in range(1,n+1):
sum = sum + i
print(" sum of first ",n," +ve natural no.s",sum)
Output:- sum of first 4 +ve natural no.s 10
13. #Demonstrate the :
#a) Use of tuples ,list,dictionary in a python program
#b) Apply the various functions available for each.

# Tuples
t = (1, 2, 3)
print("Tuple:", t)
print("First element:", t[0])
print("\nTuple length:", len(t))
print("Tuple max value:", max(t))
print("Tuple min value:", min(t))

Output:-
Tuple: (1, 2, 3)
First element: 1
Tuple length: 3
Tuple max value: 3
Tuple min value: 1

Tejas Garad 211106068 Batch A


# Lists
l= [10, 20, 30]
print("\nList:", l)
l.append(40)
print("Appended List:", l)
print("\nList length:", len(l))
print("Sum of List elements:", sum(l))
l.sort()
print("Sorted List:", l)

Output:-
List: [10, 20, 30]
Appended List: [10, 20, 30, 40]
List length: 4
Sum of List elements: 100
Sorted List: [10, 20, 30, 40]

# Dictionary
d = {'name': 'John', 'age': 25, 'city': 'New York'}
print("\nDictionary:", d)
print("Name:", d['name'])
d['job'] = 'Engineer'
print("Updated Dictionary:", d)
print("\nDictionary keys:", d.keys())
print("Dictionary values:", d.values())
print("Is 'age' key in the dictionary?", 'age' in d)

Output:-
Dictionary: {'name': 'John', 'age': 25, 'city': 'New York'}
Name: John
Updated Dictionary: {'name': 'John', 'age': 25, 'city': 'New York', 'job': 'Engineer'}
Dictionary keys: dict_keys(['name', 'age', 'city', 'job'])
Dictionary values: dict_values(['John', 25, 'New York', 'Engineer'])
Is 'age' key in the dictionary? True

Tejas Garad 211106068 Batch A


14.#Python program which accepts the user's first and last
name and print them in reverse order with a space between them
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
full_name =last_name + ' ' +first_name
print("Reversed Name:", full_name)
Output:-
Enter your first name: tejas
Enter your last name: garad
Reversed Name: garad tejas

15.#Python program to solve (x + y) * (x + y)


x = float(input("Enter the value of x: "))
y = float(input("Enter the value of y: "))
result = (x + y) * (x + y)
print("The result of (x + y) * (x + y) is:", result)
Output:-
Enter the value of x: 5
Enter the value of y: 6
The result of (x + y) * (x + y) is: 121.0

16.#Python program which accepts a character and checks if it


is an alphabet or a number and displays appropriate message to
the user
char = input("Enter a character: ")
if char.isalpha():
print(f"'{char}' is an alphabet.")
elif char.isdigit():
print(f"'{char}' is a number.")
else:
print(f"'{char}' is neither an alphabet nor a number.")
Output:-
Enter a character: 6
'6' is a number.

Conclusion:- Basic python programming were studied and implemented successfully.

Tejas Garad 211106068 Batch A

You might also like