0
Q:

sort half in ascendng and descending array

# Python 3 program to print first half  
# in ascending order and the second half 
# in descending order 
  
# function to print half of the array in  
# ascending order and the other half in  
# descending order 
def printOrder(arr, n): 
  
    # sorting the array 
    arr.sort() 
  
    # printing first half in ascending  
    # order 
    for i in range(n // 2):  
        print(arr[i], end = " ")  
  
    # printing second half in descending  
    # order 
    for j in range(n - 1, n // 2 -1, -1) : 
        print(arr[j], end = " ") 
  
# Driver code 
if __name__ == "__main__": 
      
    arr = [ 5, 4, 6, 2, 1, 3, 8, -1 ] 
    n = len(arr) 
    printOrder(arr, n) 
0
take user inputs for Month and year in integer
Month = int(input('Enter the Month :'))
Year = int(input('Enter the Year :'))
#Check condition for Month and leap year
if(Month == 2 and (Year%4 == 0) or ((Year%100 == 0) and (Year%400 == 0))):
    #if condition is TRUE
    print('Number of days is 29')
#if False check for other conditions
elif(Month == 2):
    print('Number of days is 28')
elif(Month == 1 or Month == 3 or Month == 5 or Month == 7 or Month == 8 or Month == 10 or Month == 12):
    print('Number of days is 31')
else:
    print('Number of days is 30')
0
# Python program to print first half in  
# ascending order and the second half 
# in descending order 
  
  
# function to print half of the array in  
# ascending order and the other half in  
# descending order 
def printOrder(arr,n) : 
      
    # sorting the array 
    arr.sort() 
   
    # printing first half in ascending  
    # order 
    i = 0
    while (i< n/ 2 ) : 
        print arr[i], 
        i = i + 1
          
    # printing second half in descending  
    # order 
    j = n - 1
    while j >= n / 2 : 
        print arr[j], 
        j = j - 1
          
# Driver code 
arr = [5, 4, 6, 2, 1, 3, 8, 9, 7] 
n = len(arr) 
printOrder(arr, n) 

0

New to Communities?

Join the community