0% found this document useful (0 votes)
6 views5 pages

Electronics Practical

The document contains Python programming exercises including finding the sum and difference of two numbers, calculating the area and perimeter of a triangle, appending a name to a list, sorting a dictionary, and outlining the syntax for various Python data types. Each exercise is accompanied by example code and expected outputs. Additionally, it covers numeric, sequence, set, mapping, boolean, binary, and None types in Python.

Uploaded by

shwetasatav22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Electronics Practical

The document contains Python programming exercises including finding the sum and difference of two numbers, calculating the area and perimeter of a triangle, appending a name to a list, sorting a dictionary, and outlining the syntax for various Python data types. Each exercise is accompanied by example code and expected outputs. Additionally, it covers numeric, sequence, set, mapping, boolean, binary, and None types in Python.

Uploaded by

shwetasatav22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Electronics Practical : Python Programming

Q.1. Write a python program to find Sum and difference of a=20, b=11.
a=20
b=11
sum_result=a+b
difference_result=a-b
print("Sum:",sum_result)
Output:
Sum: 31
print("Difference:",difference_result)
Output:
Difference: 9

Q.2. write a python program to find area and perimeter of a triangle.


import math
def triangle_perimeter(a,b,c):
return a+b+c
def herons_area(a,b,c):
s=(a+b+c)/2
return math.sqrt(s*(s-a)*(s-b)*(s-c))
print("Enter the sides of the triangle:")
Output:
Enter the sides of the triangle:
a=float(input("Side 1:"))
Output:
Side 1: 3
b=float(input("Side 2:"))
Output:
Side 2: 4
c=float(input("Side 3:"))
Output:
Side 3: 6
if a+b>c and a+c>b and b+c>a:
perimeter=triangle_perimeter(a,b,c)
area = herons_area(a, b, c)
print(f"Perimeter of the triangle:{perimeter}")
Output:
Perimeter of the triangle:13.0
print(f"Area of the triangle:{area:2f}")
Output:
Area of the triangle:5.33
Q.3. Write a python program to append name in the given below list ?
Names = ["Joseph", "Peter", "Cook", "Tim"]
Names=["Joseph","Peter","Cook","Tim"]
def append_name(name):
Name.append(name)
print("Updated List:",Names)
Output:
Updated List: ['Joseph', 'Peter', 'Cook', 'Tim']
new_name=input("Enter a name to append:Nooh")
Output:
Enter a name to append:Nooh

Q.4. Write a python program to sort the given dictionary.


names = {1:’Alice’, 2:’John’, 4:’Peter’, 3:’Andrew’, 6:’Ruffalo’, 5:’Chris’}
names={1:'Alice',2:'John',4:'Peter',3:'Andrew',6:'Ruffalo',5:'Chris'}
sorted_names=dict(sorted(names.items()))
print("Sorted Dictionary:",sorted_names)
Output:
Sorted Dictionary: {1: 'Alice', 2: 'John', 3: 'Andrew', 4: 'Peter', 5: 'Chris', 6: 'Ruffalo'}
Q.5. Write syntax of all data types of python language.
1. Numeric Types
a. Integer (int)
num_int = 10
b. Floating Point (float)
num_float = 10.5
c. Complex Number (complex)
num_complex = 3 + 4j
2. Sequence Types
a. String (str)
text = "Hello, Python!"
b. List (list)
my_list = [1, 2, 3, "apple", 4.5]
c. Tuple (tuple)
my_tuple = (1, 2, 3, "banana", 5.6)
d. Range (range)
my_range = range(5)
3. Set Types
a. Set (set)
my_set = {1, 2, 3, 4, 5} # Example of a set
b. Frozen Set (frozenset)
my_frozenset = frozenset([1, 2, 3, 4, 5])
4. Mapping Type
a. Dictionary (dict)
my_dict = {"name": "Alice", "age": 25, "city": "New York"}

5. Boolean Type
a. Boolean (bool)
is_valid = True

6. Binary Types
a. Bytes (bytes)
my_bytes = b"Hello"
b. Bytearray (bytearray)
my_bytearray = bytearray(5)
c. Memoryview (memoryview)
my_memoryview = memoryview(bytes(5))

7. None Type
a. NoneType (None)
my_var = None

You might also like