Edap Internal
Edap Internal
Aim: To write a Python program to find the exponentiation of a number Write a Python program to find first n prime numbers.
Write a Python program to find GCD of two numbers. Program: Aim: To write a Python program to find first n prime
Aim: To write a Python program to find GCD of two numbers. def exponentiation(base,exponent): numbers
Program: result=1 Program:
def gcd(a,b): for _ in range(exponent): def isPrime(num):
while b!=0: result *= base if num <=1:
a,b=b,a%b return result return False
return a base=float(input("Enter the base number:")) for i in range(2,int(num**0.5)+1):
n1=int(input("Enter the first number")) exponent = int(input("Enter the exponent:")) if num%i==0:
n2=int(input("Enter the second number")) result = exponentiation(base,exponent) return False
result=gcd(n1,n2) print("Result of",base,"raised to the power of",exponent,"is",result) return True
print("the gcd of two numbers is:",result) Output: def printPrime(n):
Output: Enter the base number:2 count=0
Enter the first number36 Enter the exponent:3 num=2
Enter the second number48 Result of 2.0 raised to the power of 3 is 8.0 while count<n:
if isPrime(num):
the gcd of two numbers is: 12
Experiment 4 print(num,end=" ")
count += 1
Experiment 2:
Write a Python Program to find the maximum from a list num+=1
of numbers n=int(input("Enter the value of n:"))
Write a Python Program to find the square root of a number by Newton’s
Aim: To write a Python Program to find the maximum print("First",n,"prime numbers are:")
Method printPrime(n)
Aim: To write a Python Program to find the square root of a number by from a list of numbers.
Program: Output:
Newton’s Method. Enter the value of n:10
Program: def findMax(numbers):
if not numbers: First 10 prime numbers are:
def newtonSqrt(n): 2 3 5 7 11 13 17 19 23 29
return None
guess = n/2
max_num = numbers[0]
while True: Experiment 6
for num in numbers:
new_guess=0.5*(guess+n/guess) Program to find all prime numbers within a given x
if num>max_num:
if abs(new_guess-guess)<1e-9: number.
max_num=num
return new_guess Aim: To write a Python program to find all prime
return max_num
guess=new_guess num_list=[5,3,9,1,7,2] numbers within a given range
n=float(input("Enter a number:")) print(“list is:”, num_list) Program:
sqrt=newtonSqrt(n) maximum=findMax(num_list) def isPrime(num):
print("Square root of",n,"is approximately:",sqrt) print("Maximum number in the list:",maximum) if num <=1:
Output: Output: return False
Enter a number:25 list is: [5, 3, 9, 1, 7, 2] for i in range(2,int(num**0.5)+1):
Square root of 25.0 is approximately: 5.0 Maximum number in the list: 9 if num%i==0:
return False
Experiment 3: return True
Experiment 14
Drawing random dots in
order Aim: To draw a random
dots in order Program:
import turtle
bob =
turtle.Turtle()
dot_distance =
25 width = 5
height = 7
bob.penup()
# Finish drawing
turtle.done()
Output:
Experiment 15 Python program to demonstrate tangent circle
Drawing a spiral drawing
square Aim: To draw a Program:
spiral square Program: import turtle t =
import turtle turtle.Turtle() #
radius for smallest
# Set up the window circle r = 10 #
my_wn = number of circles n =
turtle.Screen() 10
my_wn.bgcolor("light # loop for printing tangent
blue") circles for i in range(1, n +
my_wn.title("Turtle") Experiment 16 1, 1): t.circle(r * i)
Aim: Turtle program to draw coloured spiral Output:
# Set up the turtle octagon
my_pen = Program:
turtle.Turtle() import turtle as t
my_pen.color("black") colors=["red", "blue", "yellow", "green", "purple", "orange"]
#t.reset()
def my_sqrfunc(size): for i in t.tracer(0,0)
range(4): for i in
# Loop to draw a square range(45):
my_pen.fd(size) t.color(colors[i%6])
my_pen.left(90) t.pendown()
size = size - 5 # Decrease the size for the next square t.forward(2+i*5)
t.left(45)
# Drawing squares of decreasing sizes t.width(i)
my_sqrfunc(146) t.penup()
my_sqrfunc(126) t.update()
my_sqrfunc(106) t.done()
my_sqrfunc(86) Experiment 18
Output: Aim: Program to draw colored rose using spiral
my_sqrfunc(66)
my_sqrfunc(46) hexagons
my_sqrfunc(26) Program:
# Finish and close the turtle window import turtle
t=
turtle.done()
turtle.Turtle(
Output: )
list1 =
["purple","red","orange","blue","gr
Experiment een"] turtle.bgcolor("black") for i in
17 Aim: range(200): t.color(list1[i%5])
Experiment 19
Aim: Turtle program to draw Olympics
symbol Experiment 21
Program: Aim: Drawing stars and moon
#program to draw Olympic
Experiment Program:
symbol import turtle #
20 Aim:
object tr for turtle tr = # importing libraries
Turtle design of spiral square and hexagon
turtle.Turtle()
Program:
tr.color("black") import turtle
import turtle as t pen=t.Turtle()
tr.penup()
tr.goto(0, -25) import random
pen.color("cyan")
tr.pendown()
pen.speed(0) # creating turtle object
tr.circle(45)
def
tr.color("red") t = turtle.Turtle()
draw_square():
tr.penup()
for side in # to activate turtle graphics
tr.goto(110, -25)
range(4): Screen
tr.pendown()
pen.forward(100)
tr.circle(45)
pen.right(90) w = turtle.Screen()
tr.color("yellow")
for side in
tr.penup() # setting speed of turtle
range(4):
tr.goto(-55, -75)
t.speed(0) # stars at random x,y value t.end_fill()
t.right(144) t.down()