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
32 changes: 32 additions & 0 deletions Date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
print("the program is Run and Executed by Karan Shah 1812054")

year = int(input("Input a year: "))
if (year % 400 == 0):
leap_year = True
elif (year % 100 == 0):
leap_year = False
elif (year % 4 == 0):
leap_year = True
else:
leap_year = False
month = int(input("Input a month [1-12]: "))
if month in (1, 3, 5, 7, 8, 10, 12):
month_length = 31
elif month == 2:
if leap_year:
month_length = 29
else:
month_length = 28
else:
month_length = 30
day = int(input("Input a day [1-31]: "))
if day < month_length:
day += 1
else:
day = 1
if month == 12:
month = 1
year += 1
else:
month += 1
print("The next date is [yyyy-mm-dd] %d-%d-%d." % (year, month, day))
Binary file added PROBLEM STATEMENT PYTHON (1) (1).pdf
Binary file not shown.
35 changes: 35 additions & 0 deletions Prog_no_10bst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

class TreeNode(object):
def __init__(self, x):
self.val = x
self.left = None
self.right = None

def is_BST(root):
stack = []
prev = None

while root or stack:
while root:
stack.append(root)
root = root.left
root = stack.pop()
if prev and root.val <= prev.val:
return False
prev = root
root = root.right
return True

root = TreeNode(2)
root.left = TreeNode(1)
root.right = TreeNode(3)

result = is_BST(root)
print(result)

root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)

result = is_BST(root)
print(result)
15 changes: 15 additions & 0 deletions Prog_no_11selectsort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

def selectionSort(nlist):
for fillslot in range(len(nlist)-1,0,-1):
maxpos=0
for location in range(1,fillslot+1):
if nlist[location]>nlist[maxpos]:
maxpos = location

temp = nlist[fillslot]
nlist[fillslot] = nlist[maxpos]
nlist[maxpos] = temp

nlist = [14,46,43,27,57,41,45,21,70]
selectionSort(nlist)
print(nlist)
12 changes: 12 additions & 0 deletions Prog_no_13student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

from collections import Counter
classes = (
('V', 1),
('VI', 1),
('V', 2),
('VI', 2),
('VI', 3),
('VII', 1),
)
students = Counter(class_name for class_name, no_students in classes)
print(students)
6 changes: 6 additions & 0 deletions Prog_no_1calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

a=int(input())
b=int(input())
print (a+b)
print (a-b)
print (a*b)
16 changes: 16 additions & 0 deletions Prog_no_2leap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

def is_leap(year):
leap = False

# Write your logic here
if year % 400 == 0:
leap = True
elif year % 100 == 0:
leap = False
elif year % 4 == 0:
leap = True

return leap

year = int(input())
print(is_leap(year))
7 changes: 7 additions & 0 deletions Prog_no_3word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
pass
d = OrderedCounter(input()for_in range(int(input())))
print(len(d))
print(*d.values())
18 changes: 18 additions & 0 deletions Prog_no_4gcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

data = input()
li = data.split()

a = int(li[0])
b = int(li[1])

def gcd(a, b):
if (a == 0):
return b;
return gcd(b%a, a);

if (a>0 and a<(10**12+1) and b>=1 and b<(10**12+1)):
count = 1
for i in range(2, gcd(a, b)+1):
if a%i==0 and b%i==0:
count = count+1
print(count)
26 changes: 26 additions & 0 deletions Prog_no_5duplicateremove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

def removeDuplicate(str, n):

# Used as index in the modified string
index = 0

# Traverse through all characters
for i in range(0, n):

# Check if str[i] is present before it
for j in range(0, i + 1):
if (str[i] == str[j]):
break

# If not present, then add it to
# result.
if (j == i):
str[index] = str[i]
index += 1

return "".join(str[:index])

# Driver code
str= input()
n = len(str)
print(removeDuplicate(list(str), n))
22 changes: 22 additions & 0 deletions Prog_no_6matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

m,n=map(int,input().split())
l1=[]
for i in range(n):
l1.append(list(map(int,input().split())))
minormax=[]
#rowwise
for i in range(n):
minormax.append(min(l1[i]))
minormax.append(max(l1[i]))
l2=[]
for i in range(m):
c=[]
for j in range(n):
c.append(l1[j][i])
l2.append(c)
for i in range(m):
minormax.append(min(l2[i]))
minormax.append(max(l2[i]))

g= list(dict.fromkeys(minormax))
print(len(g))
13 changes: 13 additions & 0 deletions Prog_no_7stringpoor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

def not_poor(str1):
snot = str1.find('not')
spoor = str1.find('poor')


if spoor > snot and snot>0 and spoor>0:
str1 = str1.replace(str1[snot:(spoor+4)], 'good')
return str1
else:
return str1
print(not_poor('The lyrics is not that poor!'))
print(not_poor('The lyrics is poor!'))
15 changes: 15 additions & 0 deletions Prog_no_8temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

temp = input("Input the temperature you like to convert? (e.g., 45F, 102C etc.) : ")
degree = int(temp[:-1])
i_convention = temp[-1]

if i_convention.upper() == "C":
result = int(round((9 * degree) / 5 + 32))
o_convention = "Fahrenheit"
elif i_convention.upper() == "F":
result = int(round((degree - 32) * 5 / 9))
o_convention = "Celsius"
else:
print("Input proper convention.")
quit()
print("The temperature in", o_convention, "is", result, "degrees.")
9 changes: 9 additions & 0 deletions Prog_no_9sumseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2)

print(sum_series(6))
print(sum_series(10))
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# IP-LP3-SUBMISSION-PYTHON
Here are some of the question solved of LP3 task of python group.
17 changes: 17 additions & 0 deletions Traingle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


print("the code is Run and Executed by KARAN SHAH 1812054 ")

def classify(x,y,z):
if x == y == z:
return "Equilateral triangle"
elif x==y or y==z or z==x:
return "isosceles triangle"
else:
return "Scalene triangle"

print("Input lengths of the triangle sides- ")
x = int(input("x= "))
y = int(input("y= "))
z = int(input("z= "))
print(classify(x,y,z))
25 changes: 25 additions & 0 deletions chess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

print("the code is Run and Executed by KARAN SHAH 1812054 ")

inp="a1"
code='abcdefgh'
inp[0]

code.index(inp[0])
row_pos=int(code.index(inp[0]))+1
col_pos=int(inp[-1])
(row_pos+col_pos)%2


code="abcdefgh"
cell=input("enter a cell label:")
col_pos=int(code.index(cell[0]))+1
row_pos=int(cell[-1])
pos=row_pos+col_pos
print("the cell is white") if pos%2==1 else print("the cell is black")