Programming Assignment-1: Marks distribution
Given a list A of n elements, representing the marks. There are m students and you have to distribute the marks from the list A to m students such that:
1) Each student gets marks.
2) The difference between the maximum marks and minimum marks given to the students is minimised.
Input Format:
The first line contains the value n and m respectively separated by a space.
The second line contains the elements of list A separated by a space
Output Format:
Print the minimum difference
Example:
Input:
7 3
7 3 2 4 8 12 56
Output:
2
Explanation:
We need to pick 3 marks for three students (m=3). If we pick 2, 3 and 4, the difference is minimum which is 2
Given a list A of n elements, representing the marks. There are m students and you have to distribute the marks from the list A to m students such that:
1) Each student gets marks.
2) The difference between the maximum marks and minimum marks given to the students is minimised.
Input Format:
The first line contains the value n and m respectively separated by a space.
The second line contains the elements of list A separated by a space
Output Format:
Print the minimum difference
Example:
Input:
7 3
7 3 2 4 8 12 56
Output:
2
Explanation:
We need to pick 3 marks for three students (m=3). If we pick 2, 3 and 4, the difference is minimum which is 2
Program:
n,m=input().split(" ") n=int(n) m=int(m) ip=[int(i) for i in input().split(" ")] new=sorted(ip) i=0 mdf=new[n-1]-new[0] x=[] while i+m <= n: if new[m+i-1]-new[i] < mdf: x.append(new[m+i-1]-new[i]) i+=1 print(min(x),end='')
Programming Assignment-2: String Sort
Write a program that accepts a comma-separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.
Input Format:
The first line of input contains words separated by the comma.
Output Format:
Print the sorted words separated by the comma.
Example:
Input:
without,hello,bag,world
Output:
bag,hello,without,worl
d
Program:
y=input()
y=y.split(",")
y=sorted(y)
print (",".join(y),end='')
Programming Assignment-3: Push the zero
Write a Python program to push all zeros to the end of a given list a. The order of the elements should not change.
Input Format:
Elements of the list a with each element separated by a space.
Output Format:
Elements of the modified list with each element separated by a space. After the last element, there should not be any space.
Example:
Input:0 2 3 4 6 7 10
Output:2 3 4 6 7 10 0
Explanation:
There is one zero in the list. After pushing it at the end the elements of the list becomes 2 3 4 6 7 10 0. The order of other elements remains the same.
n=[int(i) for i in input().split(" ")] x=len(n) c=n.count(0) for i in range(c): n.remove(0) n.append(0) for i in range(x): if i==x-1: print(n[i],end='') else: print(n[i],end=' ')
Sir week 11 digital circuits answers ?
ReplyDeleteDigital circuits assignment 11 answers?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood Post. I like your blog. Thanks for Sharing.
ReplyDeletePython Course in Noida
This comment has been removed by the author.
ReplyDeleteThanks for sharing. it is very important for us. nice blog.
ReplyDeletecheap Student accommodation
EssayBishop
ReplyDeleteNeed help in quality essay writing? Our online dissertation, research paper and assignment writing tutors help 24/7 with the cheapest price,15% Discount.
to get more - https://www.essaybishop.com/
kuşadası
ReplyDeletemilas
çeşme
bağcılar
tunceli
56K