Given three single digit numbers, write a code to find the largest number with smallest middle digit. For example, given the input as 3, 9, 8 the number to be formed is 938.
Input Format
First line contains the first single digit number, d1
Next line contains the second single digit number, d2
Next line contains the third single digit number, d3
Output Format
Print the number formed
Why is my code wrong?
d1=int(input())
d2=int(input())
d3=int(input())
lists=[d1,d2,d3]
y=lists.sort()
a=y[2]
b=y[1]
c=y[0]
num=(int(a)*100) (int(c)*10) int(b)
print(num)
CodePudding user response:
.sort()
modifies the original list without returning a value, what you want here is this:
d1=int(input())
d2=int(input())
d3=int(input())
lists=[d1,d2,d3]
lists.sort()
a=lists[2]
b=lists[1]
c=lists[0]
num=(int(a)*100) (int(c)*10) int(b)
print(num)