Practical 1: Python Program to Print 'Hello World'
Objective:
To understand the basic syntax of Python by printing a message.
Theory/Concept:
The 'Hello World' program is often the first program written in any programming language to
understand the basic syntax and print functionality. In Python, the print() function is used to display
output.
Algorithm:
1. Start the program.
2. Use the print() function to display the message 'Hello World'.
3. End the program.
Code:
```python
# Program to print Hello World
print('Hello World')
```
Output:
'Hello World'
Conclusion:
This program helped me understand how to print messages in Python.
Practical 2: Python Program to Find the Absolute Value
Objective:
To learn how to calculate the absolute value of a number in Python.
Theory/Concept:
The absolute value of a number is its non-negative value. In Python, the abs() function is used to
find the absolute value.
Algorithm:
1. Take input from the user for a number.
2. Use the abs() function to calculate the absolute value.
3. Display the result.
Code:
```python
# Program to find the absolute value of a number
num = float(input('Enter a number: '))
print('The absolute value is:', abs(num))
```
Output:
Enter a number: -5
The absolute value is: 5.0
Conclusion:
This program helped me understand how to calculate the absolute value of a number using Python.
Practical 3: Python Program to Sort 3 Numbers
Objective:
To sort three numbers in ascending order using Python.
Theory/Concept:
Sorting is the process of arranging numbers or elements in a specific order. In Python, the sorted()
function is used to arrange elements in ascending order.
Algorithm:
1. Take three numbers as input from the user.
2. Store them in a list.
3. Use the sorted() function to sort the list.
4. Display the sorted numbers.
Code:
```python
# Program to sort 3 numbers
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))
num3 = float(input('Enter third number: '))
numbers = [num1, num2, num3]
sorted_numbers = sorted(numbers)
print('Sorted numbers:', sorted_numbers)
```
Output:
Enter first number: 3
Enter second number: 1
Enter third number: 2
Sorted numbers: [1.0, 2.0, 3.0]
Conclusion:
This program taught me how to sort numbers in Python using the sorted() function.