def squareRoot(n):
x = n
y = 1
e = 0.000001
while (x - y > e):
x = (x + y) / 2
y = n/x
return x
def findMaximumHeight(N):
n = 1 + 8*N
maxh = (-1 + squareRoot(n)) / 2
return int(maxh)
N = 12
print(findMaximumHeight(N))
Solve Problems by Coding Solutions - A Complete solution for python programming
def squareRoot(n):
x = n
y = 1
e = 0.000001
while (x - y > e):
x = (x + y) / 2
y = n/x
return x
def findMaximumHeight(N):
n = 1 + 8*N
maxh = (-1 + squareRoot(n)) / 2
return int(maxh)
N = 12
print(findMaximumHeight(N))
import math
def productPrimeFactors(n):
product = 1
if (n % 2 == 0):
product *= 2
while (n%2 == 0):
n = n/2
for i in range (3, int(math.sqrt(n)), 2):
if (n % i == 0):
product = product * i
while (n%i == 0):
n = n/i
if (n > 2):
product = product * n
return product
n = 44
print (int(productPrimeFactors(n)))
import numpy as np
arr = [[14, 17, 12, 33, 44],
[15, 6, 27, 8, 19],
[23, 2, 54, 1, 4,]]
print("\narr : \n", arr)
print("\n50th Percentile of arr, axis = None : ",
np.percentile(arr, 50))
print("0th Percentile of arr, axis = None : ",
np.percentile(arr, 0))
print("\n50th Percentile of arr, axis = 0 : ",
np.percentile(arr, 50, axis =0))
print("0th Percentile of arr, axis = 0 : ",
np.percentile(arr, 0, axis =0))
import turtle
screen=turtle.Screen()
screen.setup(800,800)
trtl = turtle.Turtle()
screen.title("3-D CUBES")
trtl.penup()
trtl.setposition(0,0)
trtl.setheading(90)
trtl.color('red')
def hexagon():
for i in range(6):
trtl.fd(50)
trtl.rt(60)
i = 1
while i < 7:
trtl.pendown()
hexagon()
trtl.right(60)
i = i + 1
import re
def isValidURL(str):
regex = ("((http|https)://)(www.)?" +
"[a-zA-Z0-9@:%._\\+~#?&//=]" +
"{2,256}\\.[a-z]" +
"{2,6}\\b([-a-zA-Z0-9@:%" +
"._\\+~#?&//=]*)")
p = re.compile(regex)
if (str == None):
return False
if(re.search(p, str)):
return True
else:
return False
url = "https://www.pythonforengineers.in"
if(isValidURL(url) == True):
print("Yes")
else:
print("No")
def pattern(n):
for i in range(1,n+1):
k =i + 1 if(i % 2 != 0) else i
for g in range(k,n):
if g>=k:
print(end=" ")
for j in range(0,k):
if j == k - 1:
print(" * ")
else:
print(" * ", end = " ")
n = 10
pattern(n)
def charCount(word):
dict = {}
for i in word:
dict[i] = dict.get(i, 0) + 1
return dict
def possible_words(lwords, charSet):
for word in lwords:
flag = 1
chars = charCount(word)
for key in chars:
if key not in charSet:
flag = 0
else:
if charSet.count(key) != chars[key]:
flag = 0
if flag == 1:
print(word)
if __name__ == "__main__":
input = ['goo', 'bat', 'me', 'eat', 'goal', 'boy', 'run']
charSet = ['e', 'o', 'b', 'a', 'm', 'g', 'l']
possible_words(input, charSet)
import re
password = "D@m@_u0rtu9e$"
flag = 0
while True:
if (len(password)<8):
flag = -1
break
elif not re.search("[a-z]", password):
flag = -1
break
elif not re.search("[A-Z]", password):
flag = -1
break
elif not re.search("[0-9]", password):
flag = -1
break
elif not re.search("[_@$]", password):
flag = -1
break
elif re.search("\s", password):
flag = -1
break
else:
flag = 0
print("Valid Password")
break
if flag ==-1:
print("Not a Valid Password")
from turtle import *
state = {'turn': 0}
def spinner():
clear()
angle = state['turn']/10
right(angle)
forward(100)
dot(120, 'red')
back(100)
right(120)
forward(100)
dot(120, 'green')
back(100)
right(120)
forward(100)
dot(120, 'blue')
back(100)
right(120)
update()
def animate():
if state['turn']>0:
state['turn']-=1
spinner()
ontimer(animate, 20)
def flick():
state['turn']+=10
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
width(20)
onkey(flick, 'space')
listen()
animate()
done()
from tkinter import *
import calendar
def showCalender():
gui = Tk()
gui.config(background='grey')
gui.title("Calender for the year")
gui.geometry("550x600")
year = int(year_field.get())
gui_content= calendar.calendar(year)
calYear = Label(gui, text= gui_content, font= "Consolas 10 bold")
calYear.grid(row=5, column=1,padx=20)
gui.mainloop()
if __name__=='__main__':
new = Tk()
new.config(background='grey')
new.title("Calender")
new.geometry("250x140")
cal = Label(new, text="Calender",bg='grey',font=("times", 28, "bold"))
year = Label(new, text="Enter year", bg='dark grey')
year_field=Entry(new)
button = Button(new, text='Show Calender',
fg='Black',bg='Blue',command=showCalender)
cal.grid(row=1, column=1)
year.grid(row=2, column=1)
year_field.grid(row=3, column=1)
button.grid(row=4, column=1)
new.mainloop()