How to simplify function with multiple if-statements and multiple conditions?

I have a function which should output which test scores are significantly higher than the other test scores. There are four tests (a, b, c and d). The user will input the test scores and check different checkbuttons if there are significant differences between any of the test scores. There are 6 checkbuttons in total: “a & b”, “a & c”, “a & d” and so on. The user will have access to all this info beforehand.

The Problem

My current function works, but in order to cover every eventuality I would have to write out many, many if-statements:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def my_function (A_test_score, B_test_score, C_test_score, D_test_score, A_B_state, A_C_state, A_D_state, B_C_state, B_D_state, C_D_state):
A_test_score = int(a.get())
B_test_score = int(b.get())
C_test_score = int(c.get())
D_test_score = int(d.get())
# Retrieving state of the checkboxes (1 = checked)
A_B_state = A_B_var.get()
A_C_state = A_C_var.get()
A_D_state = A_D_var.get()
B_C_state = B_C_var.get()
B_D_state = B_D_var.get()
C_D_state = C_D_var.get()
final_text = ""
if A_B_state == 1:
if (A_test_score - B_test_score) > 0:
final_text += "A is significantly larger than B"
elif (A_test_score - B_test_score) < 0:
final_text += "B is significantly larger than A"
if A_C_state == 1:
if (A_test_score - C_test_score) > 0:
final_text += "nA is significantly larger than C"
elif (A_test_score - C_test_score) < 0:
final_text += "nC is significantly larger than A"
# and so on…
if A_B_state == 1 and (A_test_score - B_test_score) > 0 and A_C_state == 1 and (A_test_score - C_test_score) > 0 and A_D_state == 1 and (A_test_score - D_test_score) > 0:
return "A is significantly larger than B, C and D"
if A_B_state == 1 and (A_test_score - B_test_score) > 0 and A_C_state == 1 and (A_test_score - C_test_score) > 0:
return "A is significantly larger than B and C"
return final_text
</code>
<code>def my_function (A_test_score, B_test_score, C_test_score, D_test_score, A_B_state, A_C_state, A_D_state, B_C_state, B_D_state, C_D_state): A_test_score = int(a.get()) B_test_score = int(b.get()) C_test_score = int(c.get()) D_test_score = int(d.get()) # Retrieving state of the checkboxes (1 = checked) A_B_state = A_B_var.get() A_C_state = A_C_var.get() A_D_state = A_D_var.get() B_C_state = B_C_var.get() B_D_state = B_D_var.get() C_D_state = C_D_var.get() final_text = "" if A_B_state == 1: if (A_test_score - B_test_score) > 0: final_text += "A is significantly larger than B" elif (A_test_score - B_test_score) < 0: final_text += "B is significantly larger than A" if A_C_state == 1: if (A_test_score - C_test_score) > 0: final_text += "nA is significantly larger than C" elif (A_test_score - C_test_score) < 0: final_text += "nC is significantly larger than A" … # and so on… if A_B_state == 1 and (A_test_score - B_test_score) > 0 and A_C_state == 1 and (A_test_score - C_test_score) > 0 and A_D_state == 1 and (A_test_score - D_test_score) > 0: return "A is significantly larger than B, C and D" if A_B_state == 1 and (A_test_score - B_test_score) > 0 and A_C_state == 1 and (A_test_score - C_test_score) > 0: return "A is significantly larger than B and C" return final_text </code>
def my_function (A_test_score, B_test_score, C_test_score, D_test_score, A_B_state, A_C_state, A_D_state, B_C_state, B_D_state, C_D_state):
 
    A_test_score = int(a.get())
    B_test_score = int(b.get())
    C_test_score = int(c.get())
    D_test_score = int(d.get())
 
    # Retrieving state of the checkboxes (1 = checked)
    A_B_state = A_B_var.get()
    A_C_state = A_C_var.get()
    A_D_state = A_D_var.get()
    B_C_state = B_C_var.get()
    B_D_state = B_D_var.get()
    C_D_state = C_D_var.get()
 
    final_text = ""
 
    if A_B_state == 1:
        if (A_test_score - B_test_score) > 0:
            final_text += "A is significantly larger than B"
        elif (A_test_score - B_test_score) < 0:
            final_text += "B is significantly larger than A"
 
    if A_C_state == 1:
        if (A_test_score - C_test_score) > 0:
            final_text += "nA is significantly larger than C"
        elif (A_test_score - C_test_score) < 0:
            final_text += "nC is significantly larger than A"
 
… # and so on…
 
    if A_B_state == 1 and (A_test_score - B_test_score) > 0 and A_C_state == 1 and (A_test_score - C_test_score) > 0 and A_D_state == 1 and (A_test_score - D_test_score) > 0:
        return "A is significantly larger than B, C and D"
 
    if A_B_state == 1 and (A_test_score - B_test_score) > 0 and A_C_state == 1 and (A_test_score - C_test_score) > 0:
        return "A is significantly larger than B and C"
 
    return final_text

Disered Output

If for example the score on test a and b are significantly larger than c and d:
“a and b are significantly larger than c and d.”

And if, for example, a is larger than b, c and d, and b is larger than d:
“a is significantly larger than b, c and d.
b is larger than d.”

Thus, the goal is to avoid redundant outputs like this:
“a is significantly larger than b.
a is significantly larger than c.
a is significantly larger than d.”

I’m guessing there is a better way to to this… Can’t find anything in the previous suggested posts so far. Any thoughts?

Thanks!

New contributor

Cartilago is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật