-1
def Tempurature(Lowest, Highest):
ok = False
while not ok:
    try:
       Input = int(input(print("\nEnter the Mid-Day tempurature for Day {}:".format(Counter))))
       if Input >= Lowest and Input <= Highest:
            ok = True
            return Input
       else:
            print ("Please enter a valid number between {} and {}".format(Lowest, Highest))
    except:
        print ("Please enter a number")

So this is my Function, I use it to input numbers into an array like so

Counter = int(1)
TempDay = array.array ("i", range(31))
TempDay[Counter] = (Tempurature(-90, 60))

However when I call up the function, the following prints

Enter the Mid-Day tempurature for Day 1:
None

Any solutions on how to get rid of the "None" print to make the input line at the ":" rather than at the end of the "None"?

Maxy Picky
  • 31
  • 1
  • 8
  • try remove print in the input function – Julien Sep 17 '15 at 02:11
  • also, just for programming convention: variables, parameters, and functions (or methods if you call them that) should start with lowercase letters. Classes should start with upper case letters. If someone else were to read your code (if it were a complex program) they might get confused if they are reading over it quickly. Not a big thing though. – Connor Sep 17 '15 at 05:08

2 Answers2

0

Ditch the print call inside of your input function. input will automatically print anything inside of the input call.

Input = int(input("\nEnter the Mid-Day tempurature for Day {}:".format(Counter))))

The reason it's printing None is due to the print call; after its completion it returns None, and since input will happily print whatever you give it while blocking for input, it's printing the None as if you had intended to do that.

Makoto
  • 104,088
  • 27
  • 192
  • 230
-1

You are calling .format with a None argument.

The variable Counter is not available inside your function scope.

Also, you are actually calling input() on the return of print(), you need to pass in the string to input().

Community
  • 1
  • 1
Vikram Saran
  • 1,143
  • 8
  • 17
  • It could be defined outside of the function. Also, if it were defined to `None`, then you'd see, "Enter the Mid-Day tempurature for Day None" instead. They see a number there, so that's not an issue. – Makoto Sep 17 '15 at 02:24
  • As I mention in my answer, based on the code as given, `Counter` inside the function scope. I do also give the same response as yours regarding the return of print being passed to input. Please do not downvote answers which actually solve the issue just because you also have a pending answer. – Vikram Saran Sep 17 '15 at 02:30
  • I'm not downvoting it because I've also made an answer. I'm downvoting it because the first two parts of your answer have nothing to do with the actual problem. – Makoto Sep 17 '15 at 02:31
  • I saw two errors in his code, I answered something which solves both the queried error and another one which he will shortly experience. Am I wrong? – Vikram Saran Sep 17 '15 at 02:34
  • Yes. I told you already. `Counter` is not `None`, and you wouldn't see the same output if it *was*. Why don't you try it and see? – Makoto Sep 17 '15 at 02:35