0

I have the following function:

years=2
double_rate=(years*12)//3
number_of_rabbits=11
answer=number_of_rabbits*double_rate
print(answer)

I want to generalize the code by being able to input years and number_of_rabbits variables

years=input("select number of years: ")
print(years)
double_rate=(years*12)//3
number_of_rabbits=input("select number of rabbits: ")
print(number_of_rabbits)
answer=number_of_rabbits*double_rate
print(answer)

However the editor (sublime text) only prompts me for the first input variable. I am not able set the second one, "select number of rabbits", nor does it print the new answer

Does anyone know why this is the case?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Sublime text always had [problems](https://stackoverflow.com/questions/10604409/sublime-text-2-console-input) with `input`. – Countour-Integral Jan 10 '21 at 21:25
  • Not sure about Sublime, but you have to convert the input to `int` before you can calculate with it, e.g. `years = int(input(...))` – tobias_k Jan 10 '21 at 21:28
  • Also, not sure what you are computing here, but I think it should be `answer = number_of_rabbits * 2**double_rate` – tobias_k Jan 10 '21 at 21:30
  • 'number_of_rabbits' doubes every 3 months. So if I use the first inputs I will have 88 as the result – python_beginner Jan 10 '21 at 21:41

1 Answers1

0

The number of years you enter is saved as a string, not an int (or float). So when you try to calculate double_rate, you're multiplying a string by 12 (which is fine) and then floor dividing the result by 3, which doesn't work.

Try years = int(input("Select number of years: ")) instead.

  • thanks, am entering, say, 4 in the output section of the editor, it still doesn't prompt the second input. Is there something wrong with the double_rate line? – python_beginner Jan 10 '21 at 21:39