Loading...
More Python Posts
magnitude = lambda bits: 1_000_000_000_000_000_000 % (2 ** bits)sign = lambda bits: -1 ** (1_000_000_000_000_000_000 // (2 ** bits))print("64 bit sum:", magnitude(64) * sign(64))print("32 bit sum:", magnitude(32) * sign(32))print("16 bit sum:", magnitude(16) * sign(16))
color2 = (60, 74, 172)color1 = (19, 28, 87)percent = 1.0for i in range(101):resultRed = round(color1[0] + percent * (color2[0] - color1[0]))resultGreen = round(color1[1] + percent * (color2[1] - color1[1]))resultBlue = round(color1[2] + percent * (color2[2] - color1[2]))print((resultRed, resultGreen, resultBlue))percent -= 0.01
#question1.pydef rose(n) :if n==0 :yield []else :for k in range(0,n) :for l in rose(k) :for r in rose(n-1-k) :yield [l]+[r]+[r]def start(n) :for x in rose(n) :print(x) #basically I am printing x for each rose(n) fileprint("starting program: \n")start(2) # here is where I call the start function
#Python program to print topological sorting of a DAGfrom collections import defaultdict#Class to represent a graphclass Graph:def __init__(self,vertices):self.graph = defaultdict(list) #dictionary containing adjacency Listself.V = vertices #No. of vertices# function to add an edge to graphdef addEdge(self,u,v):self.graph[u].append(v)# A recursive function used by topologicalSortdef topologicalSortUtil(self,v,visited,stack):# Mark the current node as visited.visited[v] = True# Recur for all the vertices adjacent to this vertexfor i in self.graph[v]:if visited[i] == False:self.topologicalSortUtil(i,visited,stack)# Push current vertex to stack which stores resultstack.insert(0,v)# The function to do Topological Sort. It uses recursive# topologicalSortUtil()def topologicalSort(self):# Mark all the vertices as not visitedvisited = [False]*self.Vstack =[]# Call the recursive helper function to store Topological# Sort starting from all vertices one by onefor i in range(self.V):if visited[i] == False:self.topologicalSortUtil(i,visited,stack)# Print contents of stackprint(stack)g= Graph(6)g.addEdge(5, 2);g.addEdge(5, 0);g.addEdge(4, 0);g.addEdge(4, 1);g.addEdge(2, 3);g.addEdge(3, 1);print("Following is a Topological Sort of the given graph")g.topologicalSort()
import mysql.connectormydb = mysql.connector.connect(host="localhost",user="yourusername",password="yourpassword")mycursor = mydb.cursor()mycursor.execute("CREATE DATABASE mydatabase")
# Python Program to calculate the square rootnum = float(input('Enter a number: '))num_sqrt = num ** 0.5print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))