Python Programs
Python Programs
Python Programs
PlusMius
n = int(input().strip())
list = list(map(int,input().rstrip().split()))
pos = 0
neg = 0
zero = 0
for i in list:
if i > 0:
pos += 1
elif i < 0:
neg += 1
else:
zero += 1
#print(pos,neg,zero)
n_pos = pos/n
n_neg = neg/n
n_zero = zero/n
print(format(n_pos, '5f'))
print(format(n_neg, '5f'))
print(format(n_zero, '5f'))
---------------------------------------------------------------------------------------------------
2. MaxMin
def miniMaxSum(arr):
min_val = min(arr)
max_val = max(arr)
total_sum = sum(arr)
print(min_sum, max_sum)
---------------------------------------------------------------------------------------------------
3. TimeConversion
def timeConversion(s):
# Extract hour, minutes, seconds, and period (AM/PM)
hour, minutes, seconds = map(int, s[:-2].split(':'))
period = s[-2:]
# Example usage
s = input("Enter time in 12-hour AM/PM format: ")
result = timeConversion(s)
print("Time in 24-hour format:", result)
---------------------------------------------------------------------------------------------------
4. Lonely Integer
def lonelyinteger(a):
# Write your code here
for i in a:
x = a.count(i)
if x == 1:
f=i
elif x > 1:
continue
return f
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
result = lonelyinteger(a)
fptr.write(str(result) + '\n')
fptr.close()
---------------------------------------------------------------------------------------------------
def diagonalDifference(arr):
x = 0
y = 0
n = len(arr)
for i in range(n):
x += arr[i][i]
y += arr[i][n - i - 1]
absolute_difference = abs(x - y)
return absolute_difference
n = int(input().strip())
arr = []
for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))
print(diagonalDifference(arr))
---------------------------------------------------------------------------------------------------
6.