Milind Mali / Data Scientist / Data Analyst.
#1.basic excercise for begineers
#2.python input and output exercises
#3.python loop exercises
#4.python function exercises
#5.python string exercises
#6.python data structure exercises
#7.python list exercises
#8.python dictionary exercises
#9 python set exercises
#10.python tuple exercises
#11.python date and time exercises
#12.python OOP exercises
#13.python JSON exercises
#14.python Numpy exercises
#15.python pandas exercises
#16.python matplotlib exercises
#17.python random data generation exercises
#18.python database exercises
1. Basic Exercise for Beginners
Excercise 1: Swap the number without using third varible
localhost:8889/notebooks/Desktop/Data Science/Python Practice/Milind Mali_Python Practice_200%2B.ipynb 1/122
,6/7/23, 5:30 PM Milind Mali_Python Practice_200+ - Jupyter Notebook
In [103]:
x=int(input("enter the first number "))
y=int(input("enter the Second number "))
print(x,y)
x=x+y
y=x-y
x=x-y
print(x,y)
enter the first number 4
enter the Second number 5
4 5
5 4
Exercise 2: Write a Program to extract each digit from an integer in the reverse order.
For example, If the given int is 7536, the output shall be “6 3 5 7“, with a space separating the digits.
In [102]:
n=int(input("enter the number: "))
y=str(n)[::-1]
print(y)
type(y)
enter the number: 7536
6357
Out[102]:
str
excercise 3: Write a program that will give you the sum of 3 digits
In [35]:
x=int(input("enter three digit number"))
a=x%10 # we will get last digit
num=x//10 # integer-divison here we will get first two digit
b=num%10 # here we will get last digit of two digit number
c=num//10 # here will get first digit of two digit number
print(a+b+c)
enter three digit number567
18
localhost:8889/notebooks/Desktop/Data Science/Python Practice/Milind Mali_Python Practice_200%2B.ipynb 2/122
,6/7/23, 5:30 PM Milind Mali_Python Practice_200+ - Jupyter Notebook
excercise 4: Write a program that will reverse a four digit number.Also it checks whether the reverse is true.
In [37]:
x=int(input("enter the four digit number "))
a=x%10 # to get last number
num_1=x//10 # to get first three numbers
b=num_1%10 # this way i will get 2nd last number
num_2=num_1//10 # here will get first two digit number
c=num_2%10 # we will get 2 nd number
d=num_2//10 # here we will get 1st digit
#formula for reverse
rev=a*1000+b*100+c*10+d
print(rev)
#now let check whether both number are equal or not
if x==rev:
print(True)
else:
print(False)
enter the four digit number 4567
7654
False
excercise 5: Write a program to find the euclidean distance between two coordinates.
In [40]:
import math
localhost:8889/notebooks/Desktop/Data Science/Python Practice/Milind Mali_Python Practice_200%2B.ipynb 3/122
, 6/7/23, 5:30 PM Milind Mali_Python Practice_200+ - Jupyter Notebook
In [41]:
x1=float(input("x1: "))
y1=float(input("y1: "))
x2=float(input("x2: "))
y2=float(input("y2: "))
x=[x1,y1]
y=[x2,y2]
print("="*100)
print("Eucledian distance for given co-ordinate will be",round(math.dist(x,y),2))
x1: 4
y1: 5
x2: 6
y2: 8
==========================================================================
==========================
Eucledian distance for given co-ordinate will be 3.61
excercise 5: Write a program that will tell whether the given number is divisible by 3 & 6.
In [49]:
num=int(input("enter the number "))
if num%3==0 and num%6==0:
print("the number is divisible by 3 and 6")
else:
print("the number is not divisible by 3 and 6")
enter the number 45
the number is not divisible by 3 and 6
Excercise 6: Write a program that will take three digits from the user and add the square of each digit.
In [53]:
n=int(input("Enter three digit number: "))
#123
a=n%10 #3
num=n//10 #12
b=num%10 #2
c=num//10 #1
output_value=(a**2)+(b**2)+(c**2)
print(output_value)
Enter three digit number: 345
50
localhost:8889/notebooks/Desktop/Data Science/Python Practice/Milind Mali_Python Practice_200%2B.ipynb 4/122