Python for Data Science
Before the starting of practical you need to configure Python IDE
1. Python Program to Print Hello world!
print('Hello, world!')
Output:
Hello, world!
=====================================================================
2. Python Program to Add Two Numbers
num1 = 1.5
num2 = 7.5
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Output:
The sum of 1.5 and 7.5 is 9
=====================================================================
3. Python Program to Find the Square Root
num = 10
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
Output:
The square root of 8.000 is 3.162
=====================================================================
4. Python Program to Swap Two Variables
x = 6
y = 7
x, y = y, x
print("x =", x)
print("y =", y)
Output:
x= 7
y= 6
=====================================================================
No comments:
Post a Comment