Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic duo #363

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions py/p1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# ***
# *****

def asterisk_tree(height,level):
if level > height:
return
for j in range(2*level-1):
print("*", end="")
print()
asterisk_tree(height, level + 1)
def asterisk_tree(height, level):
if level > height:
return
for _ in range(height - level):
print(" ", end="")
for j in range(2 * level - 1):
print("*", end="")
print()
asterisk_tree(height, level + 1)

n=int(input("Enter height of tree : "))
n = int(input("Enter height of tree: "))
asterisk_tree(n, 1)
24 changes: 13 additions & 11 deletions py/p10.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#Finding Average RGB values using the listmaker fuction to generate list of rgb values for a pixel

def listmaker(r,g,b,list1=[]):
def listmaker(r, g, b, list1=None):
if list1 is None:
list1 = []
list1.append(r)
list1.append(g)
list1.append(b)
return list1

pixel1=listmaker(23,78,34)
pixel2=listmaker(210,56,67)
pixel3=listmaker(23,78,248)
r=(pixel1[0]+pixel2[0]+pixel3[0])/3
g=(pixel1[1]+pixel2[1]+pixel3[1])/3
b=(pixel1[2]+pixel2[2]+pixel3[2])/3
rgb=[r,g,b]
print("Average RGB values of the pixels are",rgb)
pixel1 = listmaker(23, 78, 34)
pixel2 = listmaker(210, 56, 67)
pixel3 = listmaker(23, 78, 248)

r = (int(pixel1[0]) + int(pixel2[0]) + int(pixel3[0])) / 3
g = (int(pixel1[1]) + int(pixel2[1]) + int(pixel3[1])) / 3
b = (int(pixel1[2]) + int(pixel2[2]) + int(pixel3[2])) / 3

rgb = [r, g, b]
print("Average RGB values of the pixels are", rgb)
6 changes: 3 additions & 3 deletions py/p11.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Function to convert decimal to binary number

def binaryconversion(n):
print(n % 2,end = '')
if n > 1:
binaryconversion(n/2)
if n > 0:
binaryconversion(n // 2)
print(n % 2, end = '')

number=int(input("Enter Number: "))
binaryconversion(number)
Expand Down
1 change: 0 additions & 1 deletion py/p12.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Program to multiply two matrices using nested loops

A = [[1,2,3],[4,5,6],[7,8,9]]
B = [[10,11,12],[13,14,15],[16,17,18]]

Expand Down
7 changes: 5 additions & 2 deletions py/p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# input- 1 -> output- [1], input- 2 -> output- [2]

def add_item(item, items=[]):
items.append(item)
return items
if items!=[]:
items.remove(items[0])
items.append(item)
return items


print(add_item(1))
print(add_item(2))
17 changes: 8 additions & 9 deletions py/p3.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#program to remove all even numbers from the beginning of a list
#eg: [2, 4, 6, 17, 10] -> [17, 10]

def delete_starting_evens(list):
for item in list:
if list[0] % 2 == 0:
list.pop(0)
else:
break
return list
def delete_starting_evens(lst):
i = 0
while i < len(lst) and lst[i] % 2 == 0:
lst.pop(i)
return lst

lst = [2, 8, 10, 11]
print(delete_starting_evens(lst))

list = [2, 8, 10, 11]
print(delete_starting_evens(list))
8 changes: 4 additions & 4 deletions py/p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ def countSort(arr):
ans = [0 for i in range(len(arr))]
for i in arr:
count[i] += 1
for i in range(k+1):
for i in range(1, k+1):
count[i] += count[i-1]
for i in range(len(arr)-1, -1, -1):
ans[count[arr[i]]] = arr[i]
for i in range(len(arr)):
ans[count[arr[i]]-1] = arr[i]
count[arr[i]] -= 1
return ans
return ans

arr = [3, 4, 12, 2, 4, 5, 5, 6, 12, 33, 10, 1, 2, 8, 6]
ans = countSort(arr)
Expand Down
1 change: 0 additions & 1 deletion py/p5.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#recursive program to accept a number between 1 and 10 and print it

def get_number():
val1 = input('Enter a number: ')
try:
Expand Down
1 change: 0 additions & 1 deletion py/p6.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#program to perform binary addition

def addBinary(a: str, b: str) -> str:
s = []
carry = 0
Expand Down
1 change: 0 additions & 1 deletion py/p9.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import string
import sys

# Define a function named 'ispangram' that checks if a string is a pangram
def ispangram(str1, alphabet=string.ascii_lowercase):
alphaset = list(alphabet)
Expand Down