python编辑elif显示错误_python中的elif语句语法无效

对python相当陌生,但有一定的C语言经验

if语句的工作方式与C中的相同吗?将一个if语句放在另一个if语句下面以检查是否返回错误。在

我尝试在python中使用elif语句似乎有一个问题,有人能帮我弄清楚这里的问题是什么吗?在#!/usr/bin/env python3

# TODO

#import nltk

from helpers import get_user_timeline

from analyzer import Analyzer

#ZYMAYLA'S HINTS

#ensure proper usage

#argv

def main():

if len(sys.argv) != 2:

sys.exit("Usage: ./smile @username")

# absolute paths to lists

positives = os.path.join(sys.path[0], "positive-words.txt")

negatives = os.path.join(sys.path[0], "negative-words.txt")

#get tweets

##get_user_timeline (in helpers.py)

if get_user_timeline(screen_name, count=200) is False:

#Check if successful

#if private account or does not exist(unsuccessful)

#error message if unsuccessful(sys.exit)

sys.exit("account either private or does not exist")

#tokenize the tweet (like we did in analyzer.py for "smile")

#tokenizers are part of natural language toolkit

#use a TweetTokenizer to split into a list of words

#analyze tweets

#initialize Analyzer

analyzer = Analyzer(positives, negatives)

#instantiate Analyzer, iterate over every token scoring them pos,neg,neutral (this will indicate if the tweet is posistive/negative/neutral)

score = analyzer.TweetAnalyzer(sys.argv[1])

if score > 0.0:

#print score

print(colored("{}".format(score), "green", end=''))

#print tweet

print("{}".format(tweet)

elif score < 0.0:

print(colored("{}".format(score), "red", end=''))

#print tweet

print("{}".format(tweet)

else:

print(colored("{}".format(score), "yellow", end=''))

#print tweet

print("{}".format(tweet)

if __name__ == "__main__":

main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值