A source that reads numbers by large numbers after entering a value

Asked 2 years ago, Updated 2 years ago, 19 views

Other people explained the problem solving using the sort function, but if you use the for statement, I was wondering what I could do, and I was wondering if there's a way to reduce the sauce Here's the question.

a=[0,0,0,0]
sum=0
max=0

a[0]=str (input ("first digit : ")))
a[1]=str (input ("2nd digit: ")))
a[2]=str (input ("third digit: ")))
a[3]=str (input ("fourth digit: ")))


for i in range(0,4):
     for j in range(0,4):
          for k in range(0,4):
               for l in range(0,4):
                    if i!=j:
                         if i!=k:
                              if i!=l:
                                   if j!=k:
                                        if j!=l:
                                             if k!=l:
                                                  sum=a[i]+a[j]+a[k]+a[l]
                                                  if max<int(sum):
                                                       max=int(sum)
                                                  else:
                                                       continue
                                             else:
                                                  continue
                                        else:
                                             continue
                                   else:
                                        continue
                              else:
                                   continue
                         else:
                              continue
                    else:
                         continue
print ("The largest number is %d." %max)

python

2022-09-22 14:07

1 Answers

We reduced the depth of the for statement and reduced the number of entries.

But I don't know why you want to put a SORT and make a For Moon.

a=input ("Please enter 4 numbers:")split()
sum, max = 0, 0

for i in range(0,4):
     for j in range(0,4):
          for k in range(0,4):
               for l in range(0,4):
                    if i!=j and i!=k and i!=l and j!=k and j!=l and k!=l:
                          sum=a[i]+a[j]+a[k]+a[l]
                          if max<int(sum):
                               max=int(sum)
                    else:
                         continue

print ("The largest number is %d." %max)


2022-09-22 14:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.