Error: "can't multiply sequence by non-int of type 'float'"

Viewed 53

It says the error is when h (altitude) is between 11000 and 25000, so I only posted the initial stuff outside all my if loops and the specific loop where the problem is happening. Here is my code:

import math;
T = 0.0;
P = 0.0;
hString = ("What is the altitude in meters?");
h = int(hString);
e = math.exp(0.000157*h);

elif 11000 < h < 25000:
   T = -56.46;
   P = (22.65)*[(1.73)-e];
2 Answers

When you use mathematical operations you need to be careful with brackets.

    P = (22.65)*((1.73)-e); #will be right way of using

[ ] using will create a list which you, do not need in this program.

Here is a link which will help you learn much more about type conversions and proper use of brackets while doing mathematics on it.

Also in your code you have not used

      hString =input ("What is the altitude in meters?");
      h = int(hString);

input will allow you to take value from user and then int(your_input) will help you convert to integer

The square brackets in the last line ([(1.73)-e]) create a list. In this case, it's a list with one element, namely (1.73)-e. I imagine you intended those to be parens. Make that change and it will work.

The final line becomes:

P = (22.65)*((1.73)-e);
Related