mercredi 30 décembre 2020

to print maximum and minimum sum of 4 out of 5 integers inputted using random in python

In hackerrank,this question is failing 8 out of 15 testcases,can someone please correct this and tell me what is wrong.

Also I want to use random in this question and not by other methods.

import random

inputting values in list

arr=[int(x) for x in input().split()]

assigning a randomly selected large number for minimum (mini)

mini=1000000000000

maxi=0

for x in range(len(arr)-1):
    randomsum=sum(random.sample(arr,4))
    if randomsum<mini:
       mini=randomsum
    if randomsum >maxi:
       maxi=randomsum

print(mini,maxi)



Aucun commentaire:

Enregistrer un commentaire