LAB 1 Arithmetic and String Operation
Aim:
To explore Arithmetic and string operations using python 3
Task
1. Write a Python program to perform arithmetic operations on two integers.
2. Write a Python Program to find area of a triangle.
3. Write a Python code to remove 6 characters from start of given string
“Embedded Systems”
4. Write the Python code to find length of String “Computer Science”. Replace
science with Electronics.
5. Write the Python program to reverse a string from user input
Algorithm:
[Link] Arithmetic Operations on Two Integers
1. Start.
2. Input two integers `a` and `b`.
3. Calculate the addition of `a` and `b`.
4. Calculate the subtraction of `b` from `a`.
5. Calculate the multiplication of `a` and `b`.
6. Calculate the division of `a` by `b`, ensuring `b` is not zero to avoid division by zero error.
7. Output the results of addition, subtraction, multiplication, and division.
8. End.
2. Find Area of a Triangle
1. Start.
2. Input the base and height of the triangle.
3. Calculate the area using the formula: \( \text{area} = 0.5 \times \text{base} \times
\text{height} \).
4. Output the area of the triangle.
5. End.
3. Remove 6 Characters from Start of Given String "Embedded Systems"
1. Start.
2. Define the string "Embedded Systems".
3. Remove the first 6 characters from the string.
4. Output the modified string.
5. End.
4. Find Length of String "Computer Science" and Replace 'Science' with 'Electronics'
1. Start.
2. Define the string "Computer Science".
3. Calculate the length of the string.
4. Replace the substring "Science" with "Electronics".
5. Output the length of the original string and the modified string.
6. End.
5. Reverse a String from User Input
1. Start.
2. Input a string from the user.
3. Reverse the string.
4. Output the reversed string.
5. End.
Programs:
Output:
1: Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2.0
2: Area of the triangle: 25.0
3: Modified string: ed Systems
4: Length of the string: 16
Modified strina: Computer Electronics
5: Enter a string: Ruchit
Reversed string: tihcuR
Pre Lab Questions:
1. Which notation you will use to extract part of a string?
2. Convert all the characters in the string “Raspberry” to upper case using python code.
3. List the comparison and arithmetic operators used in python.
Post Lab Questions:
[Link] Python program to find area of a circle.
2. >>> str1 = 'Hello '
>>>str2 = ' World!'
print (str1 + str2)
What is the output?
Result: