Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fix Error and clenup code
#1
Hi

I would like someone help with my python code.
What I need:
1. Solve error
2. Change code to something more clear and organized

I use Linux Mint 19 Cinnamon and Python 3

I try enter with 2162 for Player A and 1600 for Player B, but error...
Quote:Enter Rating of Player A:
2162
Enter Rating of Player B:
1600

rst: 560
Traceback (most recent call last):
File "bkp_return_pe.py", line 39, in <module>
proc = diff_rating_str(Rt_A,Rt_B)
NameError: name 'diff_rating_str' is not define
[attachment=513]

import csv


Rt_A = int(input("Enter Rating of Player A:\n"))
Rt_B = int(input("Enter Rating of Player B:\n"))


def diff_rating(Rt_A, Rt_B):
    # Retorna a diferença entre 2 Ratings  
    return abs(Rt_A-Rt_B)


# Dados de um arquivo csv dentro de uma lista

tab_list = [0, 4, 11, 18, 26, 33, 40, 47, 54, 62, 69, 77, 84, 92, 99, 107,
            114, 122, 130, 138, 146, 154, 163, 171, 180, 189, 198, 207, 216,
            226, 236, 246, 257, 268, 279, 291, 303, 316, 329, 345, 358, 375,
            392, 412, 433, 457, 485, 518, 560, 620, 735]


# Pega o valor referente a diferena dos Ratings
value_chosen = diff_rating(Rt_A,Rt_B)
# Compara com o mais proximo caso não seja exato

rst = min(tab_list, key=lambda x:abs(x-value_chosen))
print("\nrst: ", rst)

# Verifica e ajusta o mais proximo caso [rst] seja maior
if rst > value_chosen:
    # rst = next((x for x in tab_list if x > rst), None)
    n = rst
    ind = tab_list.index(n)
    resultt = tab_list[ind-1]
    rst = resultt
    print("\nrst-resullt: ", rst)


# Pega o valor referente a diferena dos Ratings
proc = diff_rating_str(Rt_A,Rt_B)
print("proc: ",proc)
print("\nDiferença dos Ratings ->: ",value_chosen)


def diff_rating_str(Rt_A, Rt_B):
    # Tranposição da dif de rating para string
    # para facilitar a verificação na a coluna (4)
    if abs(Rt_B-Rt_A) < 4:
        result_val = "0Equal"
    else:
        if Rt_A < Rt_B:
            result_val = str(resultt) + "Min"
        elif Rt_A > Rt_B:
            result_val = str(resultt) + "Large"
        else:
            result_val = str(resultt) + "Equal"
    return result_val


# Faz a leitura do arquivo CSV e retorna a coluna 4
with open('rating_tab.csv') as f:
    ler = csv.reader(f)
    for row in ler:
        if proc == row[3]:

            print("Encontrado: ", row[1])
Reply


Messages In This Thread
Fix Error and clenup code - by zinho - Dec-19-2018, 09:40 PM
RE: Fix Error and clenup code - by Gribouillis - Dec-19-2018, 10:24 PM
RE: Fix Error and clenup code - by zinho - Dec-19-2018, 11:13 PM
RE: Fix Error and clenup code - by Gribouillis - Dec-20-2018, 12:29 AM
RE: Fix Error and clenup code - by Gribouillis - Dec-20-2018, 12:31 AM
RE: Fix Error and clenup code - by zinho - Dec-20-2018, 01:14 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020