Python_Practicals_Complete (1)
Python_Practicals_Complete (1)
To install Python and an IDE such as PyCharm, VS Code, or IDLE, follow these steps:
1. Download Python from python.org and install it.
2. Install an IDE such as PyCharm or VS Code.
3. Verify installation by running 'python --version' in the terminal.
Python Code:
Expected Output:
Write a Python program for performing basic input and output operations.
Explanation:
The input() function takes user input, while print() displays output.
Python Code:
Expected Output:
Python Code:
a = 10
b=5
result = (a + b) * 2 / 4
print("Result:", result)
Expected Output:
Result: 7.5
Write a Python program for solving given problem using various if statements.
Explanation:
Python Code:
Expected Output:
Enter a number: 5
Positive Number
Write a Python program for solving given problems using while loop and for
loop.
Explanation:
Python Code:
Expected Output:
1
2
3
4
5
5
4
3
2
1
Loop control statements such as break, continue, and pass alter loop execution.
Python Code:
# Using break
for i in range(1, 6):
if i == 3:
break
print(i)
# Using continue
for i in range(1, 6):
if i == 3:
continue
print(i)
Expected Output:
1
2
1
2
4
5
Python Code:
Expected Output:
[10, 30, 40, 50]
Python Code:
numbers = [1, 2, 3, 4, 5]
print("Sum:", sum(numbers))
print("Max:", max(numbers))
print("Min:", min(numbers))
print("Length:", len(numbers))
Expected Output:
Sum: 15
Max: 5
Min: 1
Length: 5
Python Code:
Expected Output:
20
4
Python Code:
my_set = {1, 2, 3}
my_set.add(4)
my_set.remove(2)
print(my_set)
Expected Output:
{1, 3, 4}
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Sample Output for Practical {i}
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Expected Output:
Python Code:
Python Code:
Expected Output: