首页 > 解决方案 > Python if 语句在使用随机输入端口时出错

问题描述

我正在尝试使用 if 语句来确定某个文本是否在输入中,并且在我使用输入随机之前它曾经可以正常工作,现在我的 if 语句返回语法错误。

command_1=input()

post_type_fg="/post-fg"
post_type_ot="/post-ot"
post_type_sb="/post-sb"
post_type_gh="/post-gh"
post_type_hym="/post-hym"

import random
post_post_count= random.randint(1,10)
temp_post_like_count= random.randint(0,((post_post_count * 2))




if  post_type_fg in command_1:
        print("You posted",command_1[8:],"in the section forum games")
        print("Post Count:", post_post_count)
        print("Like Count: (", post_like_count, "*")

else: 
    
    print("error command 1")

标签: python

解决方案


问题是由上一行引起的,即:

temp_post_like_count= random.randint(0,((post_post_count * 2))

你有不平衡的括号((超过))。如果您得到SyntaxError但指出的行没有显示任何错误,那么很有可能,该问题实际上在前一行。


推荐阅读