-1

I'm trying to do a comparison of multiple numbers and print out the result in a string type. Here's a simplified ver.

a = input()
b = input()
c = input()
Com = [a, b, c]

print (min(Com) + " is the smallest, the value is %s" %min(Com))

For example, when I input 1,2,3 to a,b,c the output will be

"1 is the smallest, the value is 1"

but what I really want is

"a is the smallest, the value is 1"

is there any func. I can use to find out the original name of 1, which is a?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Chu
  • 321
  • 2
  • 13

1 Answers1

2

As noted in the comments, your best bet is to use a dictionary, e.g., :

a = input()
b = input()
c = input()

# store the input in a dictionary with values representing the variable names
Com = {a: "a", b: "b", c: "c"}

minCom = min(Com.keys())
minComName = Com[minCom]

print(minComName + " is the smallest, the value is %s" % minCom)
Matt Pitkin
  • 3,989
  • 1
  • 18
  • 32
  • Should we still consider the conversion to ```int(input())``` first? Otherwise, this will not work - given ```a = 11, b = 2, c = 9``` it will yield ```11``` as the minimum number! OP needs to clear on this!! – Daniel Hao Feb 09 '23 at 16:37
  • I expect having the conversion to `int`s should be there, but I'll let the OP comment on whether that's what they want. – Matt Pitkin Feb 09 '23 at 16:53