def gcdExtended(a, b):
if a == 0 :
return b,0,1
gcd,x1,y1 = gcdExtended(b%a, a)
x = y1 - (b//a) * x1
y = x1
return gcd,x,y
a, b = 35,15
g, x, y = gcdExtended(a, b)
print("gcd(", a , "," , b, ") = ", g)
Solve Problems by Coding Solutions - A Complete solution for python programming
def gcdExtended(a, b):
if a == 0 :
return b,0,1
gcd,x1,y1 = gcdExtended(b%a, a)
x = y1 - (b//a) * x1
y = x1
return gcd,x,y
a, b = 35,15
g, x, y = gcdExtended(a, b)
print("gcd(", a , "," , b, ") = ", g)
import turtle as t
t.Screen().bgcolor("Black")
t.speed(15)
t.begin_fill()
t.fillcolor('#1DB954')
t.pencolor("#1DB954")
t.pensize(0)
t.circle(100)
t.end_fill()
t.penup()
t.goto(40,50)
t.pendown()
t.left(150)
t.forward(0)
t.pensize(15)
t.pencolor('black')
t.circle(80,60)
t.penup()
t.goto(50,85)
t.pendown()
t.pensize(17)
t.right(60)
t.forward(0)
t.circle(100,60)
t.penup()
t.goto(60,120)
t.pendown()
t.pensize(20)
t.right(60)
t.forward(0)
t.circle(120,60)
t.penup()
t.goto(130, 55)
t.pendown()
t.color("#1DB954")
t.write("Spotify", font=("Arial", 60, "bold"))
t.done()
from turtle import *
speed(10)
color("#0270d6")
Screen().bgcolor('black')
penup()
goto(0, 150)
pendown()
begin_fill()
forward(150)
circle(-50, 90)
forward(300)
circle(-50, 90)
forward(300)
circle(-50, 90)
forward(300)
circle(-50, 90)
forward(150)
end_fill()
color("white")
penup()
goto(140, 80)
pendown()
begin_fill()
right(180)
forward(50)
circle(80, 90)
forward(50)
right(90)
forward(80)
left(90)
forward(40)
left(90)
forward(80)
right(90)
forward(160)
left(90)
forward(55)
left(90)
forward(160)
right(90)
forward(70)
left(80)
forward(45)
left(100)
forward(80)
right(90)
forward(40)
circle(-40, 90)
forward(40)
left(90)
forward(45)
end_fill()
hideturtle()
done()
def firstPos(str, start, end):
firstChar = -1
for i in range(start, end + 1):
if (str[i] >= 'a' and str[i] <= 'z') :
firstChar = i
break
return firstChar
def lastPos(str, start, end):
lastChar = -1
for i in range(start, end - 1, -1) :
if (str[i] >= 'a' and str[i] <= 'z') :
lastChar = i
break
return lastChar
def isPalindrome(str):
firstChar = 0
lastChar = len(str) - 1
ch = True
for i in range(len(str)) :
firstChar = firstPos(str, firstChar, lastChar);
lastChar = lastPos(str, lastChar, firstChar);
if (lastChar < 0 or firstChar < 0):
break
if (str[firstChar] == str[lastChar]):
firstChar += 1
lastChar -= 1
continue
ch = False
break
return (ch)
if __name__ == "__main__":
str = "m a 343 la y a l am"
if (isPalindrome(str)):
print("YES")
else:
print("NO")
def prime(x, y):
prime_list = []
for i in range(x, y):
if i == 0 or i == 1:
continue
else:
for j in range(2, int(i/2)+1):
if i % j == 0:
break
else:
prime_list.append(i)
return prime_list
starting_range = 2
ending_range = 7
lst = prime(starting_range, ending_range)
if len(lst) == 0:
print("There are no prime numbers in this range")
else:
print("The prime numbers in this range are: ", lst)