Home > Net >  Unsupported format string passed to NoneType.__format_
Unsupported format string passed to NoneType.__format_

Time:10-29

I have a program which calculates measurements for a specific formula. The result should be displayed on console and a rows of solutions. Unfortunately, when I run this program, the error occurs. I have tried to use zip() but it didn't helped.

Here is the Traceback error:

  File "W:/Labaratorni/micro/main.py", line 34, in main
print(f'T[C] = {temperature - 273.15:.2f} \t R = {resistance:.3f}')
TypeError: unsupported format string passed to NoneType.__format__

here is my code:

import numpy as np

K = 273.15
T = [1.4, 25, 72]
R = [3440, 1175, 453]


def make_solve(temperature_kalvin: float, temperatures: list, resistances: list):
    matrix_a = []
   for element in R:
        matrix_a.append([1, np.log(element), pow(np.log(element), 3)])
    matrix_b = np.array([1 / (t   K) for t in T])
    solve = np.linalg.solve(np.array(matrix_a), matrix_b)
    return solve


def resistance_from_temperature(temperature: float, parameter_a: float, parameter_b: float, 
parameter_c: float):
    x = 1 / parameter_c * (parameter_a - 1 / temperature)
    y = pow((pow((parameter_b / (3 * parameter_c)), 3)   pow(x / 2, 2)), .5)
    result = np.exp((y - x / 2) ** (1 / 3) - (y   x / 2) ** (1 / 3)) / 7.3


def get_list_of_second_parameters():
    solves = make_solve(K, T, R)
    temperatures = np.linspace(0   K, 100   K, 101)
    resistances = [resistance_from_temperature(temperature, solves[0], solves[1], solves[2]) for temperature in temperatures]
return temperatures, resistances


def main():
     temperatures, resistances = get_list_of_second_parameters()
     for temperature, resistance in zip(temperatures, resistances):
         print(f'T[C] = {temperature - 273.15:.2f} \t R = {resistance:.3f}')
     input()
main()

CodePudding user response:

In this case resistance is return Nan, but the problem is on this line

y = pow((pow((parameter_b / (3 * parameter_c)), 3) pow(x / 2, 2)), .5)

It is not calculating the value of y.

Another problem resistance_from_temperature is not returning the value of result.

  • Related