-1

Given a list of numbers, say:

[0,0,2,4]

I need to prompt the user to pick a number between the min and max values.

For example, I want to prompt the user with:

"Enter a number between 0 and 4: " 

and have the user must input a number in that range. In order to do that, I need to calculate the min and the max values of the list.

So, if instead the list was [1,2,4,6,7], the prompt should change to:

"Enter a number between 1 and 7: "

I tried this:

input("Enter a number from {0} and {1}: ").format(min(lst),max(lst))

...however this does not work. Can anyone help?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
user5386463
  • 43
  • 2
  • 2
  • 5

2 Answers2

3

The format(...) must be a method of the string, not of the input statement. Your parentheses are wrong:

input( "Enter a number from {0} and {1}: ".format(min(lst),max(lst)) )
alexis
  • 48,685
  • 16
  • 101
  • 161
1

Your .format needs to be inside the parenthesis of input(). You are attempting to format the result of that function, not the string.

input("Enter a number from {0} and {1}: ".format(min(lst),max(lst)))
                                         ^ Parenthesis moved from here
Andy
  • 49,085
  • 60
  • 166
  • 233