0

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?

Two-Bit Alchemist
  • 16,887
  • 5
  • 44
  • 79
user5386463
  • 45
  • 2
  • 2
  • 5

2 Answers2

4

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
  • 46,350
  • 14
  • 97
  • 153
2

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
  • 46,308
  • 56
  • 161
  • 219