Skip to main content

AnyTree Randomizer

0 likes • Apr 15, 2021 • 0 views
Python
Loading...

More Python Posts

Create a Floyd’s Triangle

0 likes • May 31, 2023 • 0 views
Python
def generate_floyds_triangle(num_rows):
triangle = []
number = 1
for row in range(num_rows):
current_row = []
for _ in range(row + 1):
current_row.append(number)
number += 1
triangle.append(current_row)
return triangle
def display_floyds_triangle(triangle):
for row in triangle:
for number in row:
print(number, end=" ")
print()
# Prompt the user for the number of rows
num_rows = int(input("Enter the number of rows for Floyd's Triangle: "))
# Generate Floyd's Triangle
floyds_triangle = generate_floyds_triangle(num_rows)
# Display Floyd's Triangle
display_floyds_triangle(floyds_triangle)

screencap.py

0 likes • Jan 23, 2021 • 0 views
Python
"""
Take screenshots at x interval - make a movie of doings on a computer.
"""
import time
from datetime import datetime
import ffmpeg
import pyautogui
while 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()
)
"""

key of minimum value

0 likes • Nov 19, 2022 • 0 views
Python
def key_of_min(d):
return min(d, key = d.get)
key_of_min({'a':4, 'b':0, 'c':13}) # b

two-digit integer

0 likes • Feb 26, 2023 • 0 views
Python
#You are given a two-digit integer n. Return the sum of its digits.
#Example
#For n = 29 the output should be solution (n) = 11
def solution(n):
return (n//10 + n%10)

LeetCode Flood Fill

0 likes • Oct 15, 2022 • 0 views
Python
class Solution(object):
def floodFill(self, image, sr, sc, newColor):
R, C = len(image), len(image[0])
color = image[sr][sc]
if color == newColor: return image
def dfs(r, c):
if image[r][c] == color:
image[r][c] = newColor
if r >= 1: dfs(r-1, c)
if r+1 < R: dfs(r+1, c)
if c >= 1: dfs(r, c-1)
if c+1 < C: dfs(r, c+1)
dfs(sr, sc)
return image

Calculator

0 likes • Nov 19, 2022 • 0 views
Python
""" Calculator
----------------------------------------
"""
def addition ():
print("Addition")
n = float(input("Enter the number: "))
t = 0 //Total number enter
ans = 0
while n != 0:
ans = ans + n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def subtraction ():
print("Subtraction");
n = float(input("Enter the number: "))
t = 0 //Total number enter
sum = 0
while n != 0:
ans = ans - n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def multiplication ():
print("Multiplication")
n = float(input("Enter the number: "))
t = 0 //Total number enter
ans = 1
while n != 0:
ans = ans * n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def average():
an = []
an = addition()
t = an[1]
a = an[0]
ans = a / t
return [ans,t]
// main...
while True:
list = []
print(" My first python program!")
print(" Simple Calculator in python by Malik Umer Farooq")
print(" Enter 'a' for addition")
print(" Enter 's' for substraction")
print(" Enter 'm' for multiplication")
print(" Enter 'v' for average")
print(" Enter 'q' for quit")
c = input(" ")
if c != 'q':
if c == 'a':
list = addition()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 's':
list = subtraction()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 'm':
list = multiplication()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 'v':
list = average()
print("Ans = ", list[0], " total inputs ",list[1])
else:
print ("Sorry, invilid character")
else:
break