Getting Error with UI for TikTok algorithm

So I basically made a algorithm which takes the users input and decided on a rank from 1-100 and puts it on a UI.

import tkinter, os, webbrowser, random
#algorithm
def tiktok_algorithm(share_count, like_count, comment_count, posts):
    if (share_count >= 10000 and like_count >= 5000 and posts >20 and comment_count.find("amazing")!= -1):
        rank = 1 
    elif (share_count >= 7000 and like_count >= 2000 and posts >25 and comment_count.find("amazing")!= -1):
        rank = random.randint(2,10)
    elif (share_count >= 6000 and like_count >= 1500 and posts >25 and comment_count.find("amazing")!= -1):
        rank = random.randint(11,20)
    elif (share_count >= 5000 and like_count >= 1300 and  posts >20 and comment_count.find("amazing")!= -1):
        rank = random.randint(21,40)
    elif (share_count >= 4000 and like_count >= 1000 and  posts >15 and comment_count.find("nice")!= -1):
        rank = random.randint(41,55)
    elif (share_count >= 3000 and like_count >= 500 and  posts >11 and comment_count.find("cool")!= -1):
        rank = random.randint(56,70)
    elif (share_count >= 2000 and like_count >= 300 and posts >11 and comment_count.find("ok")!= -1):
        rank = random.randint(71,80)
    elif (share_count >= 1000 and like_count >= 150 and posts >11 and comment_count.find("ok")!= -1):
        rank = random.randint(81,90)
    elif (share_count >= 400 and like_count >= 100 and posts >11 and comment_count.find("ok")!= -1):
        rank = random.randint(91,97)
    else:
        rank = random.randint(98,100)
    return(rank)
def calculate_ranking():
    # read in the entry values
    like_count = int(likes_entry.get())
    comment_count = comment_entry.get()
    posts = int(posts_entry.get())
    shares = int(share_entry.get())
    
    rank = tiktok_algorithm(like_count, comment_count, shares, posts)
    # "print" result to result label
    result_label.config(text="Your tiktok ranking is: " + str(rank))

root = tkinter.Tk()
root.title("Magic Tiktok Algorithm")
root.geometry("400x600")

# likes
likes_label = tkinter.Label(root, text="Number of Likes:")
likes_label.pack()
likes_entry = tkinter.Entry(root)
likes_entry.pack()
# comment
comment_label = tkinter.Label(root, text="Comment:")
comment_label.pack()
comment_entry = tkinter.Entry(root)
comment_entry.pack()
#shares
share_label = tkinter.Label(root, text="number of shares:")
share_label.pack()
share_entry = tkinter.Entry(root)
share_entry.pack()
#posts
posts_label = tkinter.Label(root, text="Posts")
posts_label.pack()
posts_entry = tkinter.Entry(root)
posts_entry.pack()
#image
img_path = os.path.dirname(__file__) + "\\tiktok-tricks-09.PNG"
tiktok_image = tkinter.PhotoImage(file=img_path)
resized_tiktok_img = tiktok_image.subsample(4,4) 
image_label = tkinter.Label(root, image=resized_tiktok_img)
image_label.pack()
# rank button
rank_button = tkinter.Button(root, text="Get Ranking", command=calculate_ranking)
rank_button.pack()
# result
result_label = tkinter.Label(root, text = "Your tiktok ranking is:")
result_label.pack()
# keep the UI running
root.mainloop()

I keep getting this error, I have tried casting it to an integer, but it still doesn't work can anyone help: Do I need to change the top to str(tiktok_algorithm)

typeError: '>=' not supported between instances of 'str' and 'int'

1 answer

  • answered 2022-05-06 04:30 Axel Jacobsen

    Lets look at the error: TypeError: '>=' not supported between instances of 'str' and 'int'.

    This error occurs when you try to see if a string is >= an number. Examples of this would be "test" >= 42, or "42" >= 42. Even though the second case seems like it may work, "42" is a string an not an integer.

    Just looking at calculate_ranking, I would guess that you need comment_count = int(comment_entry.get()).

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum