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))
# Python program for Plotting Fibonacci# spiral fractal using Turtleimport turtleimport mathdef fiboPlot(n):a = 0b = 1square_a = asquare_b = b# Setting the colour of the plotting pen to bluex.pencolor("blue")# Drawing the first squarex.forward(b * factor)x.left(90)x.forward(b * factor)x.left(90)x.forward(b * factor)x.left(90)x.forward(b * factor)# Proceeding in the Fibonacci Seriestemp = square_bsquare_b = square_b + square_asquare_a = temp# Drawing the rest of the squaresfor i in range(1, n):x.backward(square_a * factor)x.right(90)x.forward(square_b * factor)x.left(90)x.forward(square_b * factor)x.left(90)x.forward(square_b * factor)# Proceeding in the Fibonacci Seriestemp = square_bsquare_b = square_b + square_asquare_a = temp# Bringing the pen to starting point of the spiral plotx.penup()x.setposition(factor, 0)x.seth(0)x.pendown()# Setting the colour of the plotting pen to redx.pencolor("red")# Fibonacci Spiral Plotx.left(90)for i in range(n):print(b)fdwd = math.pi * b * factor / 2fdwd /= 90for j in range(90):x.forward(fdwd)x.left(1)temp = aa = bb = temp + b# Here 'factor' signifies the multiplicative# factor which expands or shrinks the scale# of the plot by a certain factor.factor = 1# Taking Input for the number of# Iterations our Algorithm will runn = int(input('Enter the number of iterations (must be > 1): '))# Plotting the Fibonacci Spiral Fractal# and printing the corresponding Fibonacci Numberif n > 0:print("Fibonacci series for", n, "elements :")x = turtle.Turtle()x.speed(100)fiboPlot(n)turtle.done()else:print("Number of iterations must be > 0")
import sys# sample TuplesTuple1 = ("A", 1, "B", 2, "C", 3)Tuple2 = ("Geek1", "Raju", "Geek2", "Nikhil", "Geek3", "Deepanshu")Tuple3 = ((1, "Lion"), ( 2, "Tiger"), (3, "Fox"), (4, "Wolf"))# print the sizes of sample Tuplesprint("Size of Tuple1: " + str(sys.getsizeof(Tuple1)) + "bytes")print("Size of Tuple2: " + str(sys.getsizeof(Tuple2)) + "bytes")print("Size of Tuple3: " + str(sys.getsizeof(Tuple3)) + "bytes")
from statistics import median, mean, modedef print_stats(array):print(array)print("median =", median(array))print("mean =", mean(array))print("mode =", mode(array))print()print_stats([1, 2, 3, 3, 4])print_stats([1, 2, 3, 3])
from functools import partialdef curry(fn, *args):return partial(fn, *args)add = lambda x, y: x + yadd10 = curry(add, 10)add10(20) # 30
"""Take screenshots at x interval - make a movie of doings on a computer."""import timefrom datetime import datetimeimport ffmpegimport pyautoguiwhile True:epoch_time = int(time.time())today = datetime.now().strftime("%Y_%m_%d")filename = str(epoch_time) + ".png"print("taking screenshot: {0}".format(filename))myScreenshot = pyautogui.screenshot()myScreenshot.save(today + "/" + filename)time.sleep(5)## and then tie it together with: https://github.com/kkroening/ffmpeg-python/blob/master/examples/README.md#assemble-video-from-sequence-of-frames#"""import ffmpeg(ffmpeg.input('./2021_01_22/*.png', pattern_type='glob', framerate=25).filter('deflicker', mode='pm', size=10).filter('scale', size='hd1080', force_original_aspect_ratio='increase').output('movie.mp4', crf=20, preset='slower', movflags='faststart', pix_fmt='yuv420p').run())"""