首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tiktok algo模拟器

Tiktok algo模拟器
EN

Stack Overflow用户
提问于 2022-05-02 05:25:01
回答 2查看 99关注 0票数 1

我正在制作一个TikTok算法,这是一个代码,它基本上接受用户的输入并确定它们的等级。

代码语言:javascript
复制
import random

share_count = int(input("How many shares did you get on your last tiktok "))
like_count = int(input("How many likes did you get on your last tiktok "))
comment_count = int(input("How many comments did you get on your last tiktok "))
posts = int(input("How many posts do you have on your tiktok page "))

def magic_algorithm(share_count, like_count, comment_count, posts):
    if share_count >= 10000 and like_count > 5000 and comment_count > 200 and posts >25:
        rank = 1 
    elif share_count >= 7000 and like_count > 2000 and comment_count > 60 and posts >25:
        rank = random.randint(2,10)
    elif share_count >= 6000 and like_count > 1500 and comment_count > 50 and posts >25:
        rank = random.randint(11,20)
    elif share_count >= 5000 and like_count > 1300 and comment_count > 33 and posts >20:
        rank = random.randint(21,40)
    elif share_count >= 4000 and like_count > 1000 and comment_count > 25 and posts >15:
        rank = random.randint(41,55)
    elif share_count >= 3000 and like_count > 500 and comment_count > 15 and posts >11:
        rank = random.randint(56,70)
    elif share_count >= 2000 and like_count > 300 and comment_count > 10 and posts >11:
        rank = random.randint(71,80)
    elif share_count >= 1000 and like_count > 150 and comment_count > 10 and posts >11:
        rank = random.randint(81,90)
    elif share_count >= 400 and like_count > 100 and comment_count > 5 and posts >11:
        rank = random.randint(91,95)
    else:
        rank = random.randint(96,100)
    return rank 
print("you rank on the platform is " + magic_algorithm(share_count, like_count, comment_count, posts)) 

但出于某种原因,我遇到了一个错误:

代码语言:javascript
复制
print("you rank on the platform is " + magic_algorithm(share_count, like_count, comment_count, posts))
代码语言:javascript
复制
TypeError: can only concatenate str (not "int") to str
EN

回答 2

Stack Overflow用户

发布于 2022-05-02 05:30:40

这是因为rank是一个int,为了连接它,您需要将它转换为str

一种方法是:

代码语言:javascript
复制
return str(rank) 

第二种方法是使用f-strings

代码语言:javascript
复制
print(f"you rank on the platform is {magic_algorithm(share_count, like_count, comment_count, posts)}")
票数 2
EN

Stack Overflow用户

发布于 2022-05-02 05:26:27

代码语言:javascript
复制
print("you rank on the platform is " + str(magic_algorithm(share_count, like_count, comment_count, posts)))

这个很管用。您需要将int转换为str

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72082622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档