Skip to content
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
27 changes: 27 additions & 0 deletions December 01/Cricmetric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Reading the number of batsmen from the user
n = int(input("Enter the number of batsmen: "))

# Creating empty list to store runs of each player
run_player = []

# For loop to traverse the list
for i in range(0, n, 1):

# Reading the run of each batsman from the user
print("Enter the run scored by batsman-", i + 1, ":")
run = int(input())

# Appending the run scored to list
run_player.append(run)

# Calculating total runs by using built-in function
total_run = sum(run_player)

# Calculating the maximum runs scored
max_batsman = max(run_player)

# Printing the total runs scored
print("The total runs scored by the team is: ", total_run)

# Printing the maximum run scored by a batsman
print("The maximum run scored by a batsman is: ", max_batsman)
43 changes: 43 additions & 0 deletions December 02/Shopper's Choice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Importing statistics package
import statistics

# Reading the number of products from user
n = int(input("Enter the number of the products: "))

# Initializing product, distinct and frequency_product lists
product = []
distinct = []
frequency_product = []

# For loop to retrieve the product id
for i in range(0, n, 1):
# Reading the product id from the user
print("Enter the product id: ", end=" ")
product_id = int(input())

# Appending the product id from user
product.append(product_id)

# For loop to traverse product list
for i in product:

# If an element exists in distinct list
if i in distinct:

# If the condition is true, then perform no operation
pass

# Else if an element does not exist in distinct list
else:

# If the condition is true, then append the element to distinct list
distinct.append(i)

# For loop to traverse the distinct list
for i in distinct:

# Appending the count of each product id to frequency_product list
frequency_product.append(product.count(i))

# frequency_product is displayed
print(frequency_product)
44 changes: 44 additions & 0 deletions December 03/Sunburnt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Reading the number of buildings
n = int(input("Enter the number of buildings: "))

# Initializing the empty Height list and count variable to zero
Height = []
count = 1

# For loop to read the height of each building
for i in range(0, n, 1):

# Reading height of building
print("Enter height of building-", i + 1, ":", end=" ")
h = int(input())

# Appending the height of building to Height list
Height.append(h)

# List of buildings are displayed
print(Height)

# Intializing the variable i to zero
i = 0

# Intializing the variable j to be greater than the value of variable i
j = i + 1

# While loop when i vslue is less than number of buildings in the list
while (i < (n - 1)):

# Checking condition whether the current element is lesser than the subsequent element
if (Height[i] < Height[j]):

# Updating the count,i and j values
count = count + 1
i = i + 1
j = j + 1
else:

# Updating the i and j values only
i = i + 1
j = j + 1

# The number of buildings that will enjoy sunlight is displayed
print("The number of buildings that enjoy sunlight: ",count)
49 changes: 49 additions & 0 deletions December 04/Mirror Magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Creating empty temporary string
tempstr = " "

# Creating empty string to store reversed string
revstr = " "

# Creating empty list to store substring
substr = []

# Reading the input from user
instr = input("Enter the string: ")

# Initializing flag variable to zero
flag = 0
j = 1

# For loop to traverse string
for i in range(0, (len(instr) - 1), 1):

# While loop to access particular element
while (j < len(instr) + 1):

# Temporary variable to store value
tempstr = instr[i][j]

# Built-in function to reverse a string is used
revstr = tempstr.reversed

# Checking whether the reversed value and original value are same
if (revstr == tempstr):

# Appending values to list
substr.append(tempstr)

# Flag variable enabled
flag = 1
j = j + 1
else:
pass

# Checking whether flag variable is disabled
if (flag == 0):

# Printing error if the flag variable is still disabled
print("Error")
else:

# Printing the least value in list using built-in function
print(min(substr))
44 changes: 44 additions & 0 deletions December 05/Peaky Blinders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Empty list to store money stolen
stolen = []

# Initializing total variable to zero
total = 0

# Number of robberies
n = int(input("Enter the number of robberies: "))

# For loop to traverse the list
for i in range(0, n, 1):
# Money stolen is entered into list
r = int(input("Enter the money stolen: "))

# Appending the element to list
stolen.append(r)

# Average amount stolen
average = sum(l) / n

# Loop to locate the index of average element in stolen list
for i in range(0, n, 1):

# Checking whether an element is equal to average
if (stolen[i] == average):

# Intializinng the element to avg variable
avg = i
else:
pass

# Checking whether average value exists in the stolen list
if average in stolen:

# Traversing the list from average value
for i in range(avg, n, 1):
# Total amount of money stolen is calculated
total = total + l[i]
else:
# If average element does not exist report error
print("Error")

# Printing the total amount stolen by the thieves
print("Total amount of money stolen by the thieves: ", total)
102 changes: 102 additions & 0 deletions December 06/The Lost Algorithm Scrolls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#Initializing the lists l, temp, temp2 and output
l=[]
temp=[]
temp2=[]
output=[]

#Initializing the variables count and k to zero
count=0
k=0

#Reading the number of words
n=int(input("Enter the number of words: "))

#For loop to read the element
for i in range(n):

#Reading the elements from the user
print("Enter element: ",end=" ")
e=input()

#Appending the element to the list l
l.append(e)

# For loop to traverse the list l
for i in range(n):

# Checks if the index of next element is greater than the size of list
if (i+1)<n:

# If the length of the two consecutive words are same
if len(l[i])==len(l[i+1]):

#For loop to traverse the letters of a word
for j in range(len(l[i])):

#Appending the letter of the current word into temp list
temp.append(l[i][j])

#Appending the letter of the next word into temp list
temp2.append(l[i+1][j])

# While loop to traverse the elements of the temp list
while(k<len(temp)):

#Checking if an element of temp list does not exist in temp2 list
if temp[k] not in temp2:

# Incrementing the count variable
count=count+1

#Incrementing the control variable of the while loop
k=k+1

#If the element of temp list exists in temp2 list
else:

#Incrementing the control variable of while loop
k=k+1

#Implementing no-operation jump statement
pass

#Checking if count is not equal to 1
if (count!=1):

#If condition is true, print No valid chain
print("No valid chain")

# Checking if count is equal to 1
else:

# Checking if an element is not in output list
if l[i] not in output:

#Appending the element to output list
output.append(l[i])
# If the subsequent element exists in the output list
if l[i+1] not in output:

# Appending the subsequent element to output list
output.append(l[i+1])

#Print the output list
print(output)

# Clearing all the elements of the temp list
temp.clear()

# Clearing all the elements of temp2 list
temp2.clear()

# If the length of two consecutive words are not same
else:

# No-operation is performed
pass
# If the index of the element is greater than size of list
else:

# No-operation is performed
pass

32 changes: 32 additions & 0 deletions December 07/Baby Blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Importing all the functions from math library
from math import *


# Defining the function to solve the given problem called "Baby Blocks"
def rectangleincircle(w, h, r):
# Calcualating diagonal using Pythogaras Theorem
diagonal = sqrt(pow(w, 2) + pow(h, 2))

# Calculating diameter of the circle
diameter = r * 2

# Checking condition whether diagonal is lesser than or equal to diameter
if (diagonal <= diameter):
print("True")

# Checking condition whether diagonal is lesser than or equal to diameter
elif (diagonal > diameter):
print("False")


# Reading the width of rectangle
width = int(input("Enter the width of rectangle: "))

# Reading the height of rectangle
height = int(input("Enter the height of rectangle: "))

# Reading the radius of circle
radius = int(input("Enter the radius of circle: "))

# Calling function
rectangleincircle(width, height, radius)
51 changes: 51 additions & 0 deletions December 08/The Enchanted Forest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
def find_path(n):
if n % 2 == 0:
raise ValueError("Input must be an odd integer")

# Create an nxn matrix filled with zeros
matrix = [[0 for _ in range(n)] for _ in range(n)]

# Initialize variables for the starting position
i, j = 0, n // 2

# Fill the matrix with consecutive numbers
for num in range(1, n**2 + 1):
matrix[i][j] = num

# Update the position for the next number
i -= 1
j += 1

# Check for out-of-bounds and adjust the position accordingly
if i < 0:
i = n - 1
if j == n:
j = 0

# Check if the next position is already filled
if matrix[i][j] != 0:
i += 2
j -= 1

# Check for out-of-bounds and adjust the position accordingly
if i >= n:
i -= n

return matrix

def print_matrix(matrix):
for row in matrix:
print(row)

# Example usage
try:
n = int(input("Enter an odd integer 'n': "))
if n % 2 == 0:
raise ValueError("Input must be an odd integer")

result_matrix = find_path(n)
print("\nMatrix with equal sum of row, column, and diagonal elements:")
print_matrix(result_matrix)

except ValueError as e:
print(f"Error: {e}")
Loading