Practical 3 Aiml: Done by Anish: T20012531007
Practical 3 Aiml: Done by Anish: T20012531007
Practical 3 Aiml: Done by Anish: T20012531007
AIML
DONE BY :
ANISH
T20012531007
1) Python Program to Calculate the Average of
Numbers in a given list.
Code:
n=int(input("Enter the number of elements to
be inserted: "))
a=[]
Result:
2)Python Program to Exchange the Values of
Two Numbers Without Using a Temporary
Variable
Code:
a=int(input("Enter the value of first
variable a:"))
b=int(input("Enter the value of second
variable b:"))
a=a+b
b=a-b
a=a-b
print("a is: ",a,"b is: ",b)
Result:
Result:
Result:
Code:
n=int(input("Enter a number:"))
if n>0:
print("The number is positive")
else:
print("The number is negative")
Result:
x=x.split(" ")
x= list(map(int, x))
y=len(x)
z=sum(x)/y
if 100>z>90:
print("Your grade is A")
elif 90>z>75:
print("Your grade is B")
elif 75>z>60:
print("Your grade is C")
else:
print("You need to work harder")
Result:
7) Python Program to Print all Numbers in a Range
Divisible by a Given Number
Code:
a=int(input("Enter the lower limit:"))
b=int(input("Enter the upper limit:"))
c=int(input("Enter the number you want to
divide with:"))
for i in range(a+1,b+1):
if i%c==0:
print(i)
Result:
print("Quotient:",x/y)
print("Remainder:",x%y)
Result:
for i in range(x+1,y+1):
if i%2!=0:
print(i)
Result:
Result:
Result:
13) Python Program to Count the Number of Digits in a
Number
Code:
y=int(input("Enter any number: "))
Result:
Result:
Result:
for i in range(0,x+1):
y.append(i)
print(sum(y))
Result:
print()
Result:
Result:
Result:
simple_interest=(principle*time*rate)/100
Result:
Result:
Result:
Result:
27) Python Program to Generate all the Divisors of an
Integer
Code:
number = int(input("Enter number: "))
Result:
Result:
29) Python Program to Print Sum of Negative Numbers,
Positive Even Numbers and Positive Odd numbers in a
List
Code:
n=int(input("Enter the number of elements to
be in the list:"))
b=[]
for i in range(0,n):
a=int(input("Element: "))
b.append(a)
sum1=0
sum2=0
sum3=0
for j in b:
if(j>0):
if(j%2==0):
sum1=sum1+j
else:
sum2=sum2+j
else:
sum3=sum3+j
print("Sum of all positive even
numbers:",sum1)
print("Sum of all positive odd
numbers:",sum2)
print("Sum of all negative numbers:",sum3)
Result:
for i in range(0,total_numbers):
numbers_array.append(int(input("Number in
list : ")))
largest_even = -1
largest_odd = -1
for i in range(0,total_numbers):
if(numbers_array[i] % 2 == 0 and
numbers_array[i] > largest_even):
largest_even = numbers_array[i]
elif(numbers_array[i] % 2 != 0 and
numbers_array[i] > largest_odd):
largest_odd = numbers_array[i]
Result:
31) Python Program to Form an Integer that has the
Number of Digits at Ten's Place and the Least
Significant Digit of the Entered Integer at One's Place
Code:
n=int(input("Enter the number:"))
tmp=n
k=0
while(n>0):
k=k+1
n=n//10
b=str(tmp)
c=str(k)
d=c+b[k-1]
print("The new number formed:",int(d))
Result:
32) Python Program to Find Those Numbers which are
Divisible by 7 and Multiple of 5 in a Given Range of
Numbers
Code:
a=int(input("Lower limit:"))
b=int(input("Upper limit:"))
nl=[]
Result:
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Result:
for i in range(n):
a.append([])
a[i].append(1)
Result:
Result:
Result:
Result:
Result:
sum_x=0
sum_y=0
Result:
s = (a + b + c) / 2
Result:
43) Python Program to Check if a Number is a Prime
Number
Code:
a=int(input("Enter a number:"))
k=0
for i in range(2,a//2+1):
if(a%i==0):
k=k+1
if(k<=0):
print("Number is prime.")
else:
print("Number is not prime.")
Result:
Result:
Result:
Result:
47) Python Program to Find the Sum of First N Natural
Numbers
Code:
number=int(input("Enter a number: "))
sum = 0
while(number > 0):
sum+=number
number-=1
print("The sum of first n natural numbers
is",sum)
Result:
Result:
49) Python Program to Find the Sum of the Series: 1 +
x^2/2 + x^3/3 + … x^n/n
Code:
n=int(input("Enter the number of terms:"))
x=int(input("Enter the value of x:"))
sum1=1
for i in range(2,n+1):
sum1=sum1+((x**i)/i)
print("The sum of series is",round(sum1,2))
Result:
Result: