# Assignment 1: Python Practice

I faced some errors in happy-sad-tweets problem. To get a better understanding, I added one extra happy or sad word in a happy or sad tweet, as an example “Wow, what a great & happy day today!! #sunshine”, where I have added happy in the given problem.

I solved it by using following code. Hope may be useful as some discussion was going on about counting related errors.

Here please check the second last line is_tweet_happy = False which brings back to its initial value after completion of each inner for loop which runs for each single tweet.

Ap formula will also give same answer

I think you messed up a bit. Please check my update if not resolved. Thanks.

Hi,
Im getting 74 neutral tweets…can anyone say whats wrong with this code?

# store the final answer in this variable

number_of_neutral_tweets = 0

# perform the calculation here

for word in happy_words:
for tweet in tweets:
if word not in tweet:
number_of_neutral_tweets+=1

number_of_neutral_tweets

1 Like

I’m gettitng the following errors on running the first kernel

The loop is in reversed order according to your loop you are taking a word from the happy_list and checking if the word is not present in the tweets so if the word is not present in the tweets the count is increased by that many numbers … again you are taking the next happy word and checking if the word is not present in the tweet and again if the word is not present all tweets count without a happy word is counted . So everytime a word from the happy list is not found in tweets the count is increased by 1 and thus u are getting 74 counts
You should do like this
for tweet in tweets and then for word in happy words if word not in happy words count +=1
This is not complete code and might not give the desired result but thats how you should proceed

1 Like

Hey Everyone,
A question for all who have solved the optional exercise of cities , No matter how many days I give I am getting Paris as an answer … Say 4, 10 ,14 , 50 or 200 … I think my code is not wrong so can you tell me if this is correct or not?

anybody please tell what will be the thought process to tackle this problem

how to print the neutral tweets, i wrote a code but its not working properly.

number_of_neutral_tweets = 0

for i in tweets:
is_tweet_neutral = False
for word in sad_words + happy_words:
if word not in i:
is_tweet_neutral = True
print(i)
number_of_neutral_tweets+= 1

this was the problem

may be you forgot to run happy_words cell.
first run that cell then try.

1 Like

You already calculated number of happy tweets and sad tweets. You also have the number of tweets.

If tweet is neither happy nor sad then it’s just neutral. so

`number_of_neutral_tweets=total_number_of_tweets - (number_of_sad_tweets+number_of_happy_tweets`)

after running all the cells it is showing this.

hi
i have completed by assignment but confuse with the method of submitted. can you please hepl
my assignment url is : https://hub.gke.mybinder.org/user/api-git-6213bcb-68a6b8c75c3f_11-5mvwfkxy/notebooks/Assig1_1.ipynb

and i am not able to see the run output

1 Like

Did you save your notebook on each checkpoint.

well, in this notebook nothing is there its empty… you have to complete all the questions and after that run the last cell
that is

now go to your jovian profile and click on the notebook Python practice …
make it public and click on the share button and submit it on the link given at the end of notebook.

How to run the assignments in my local jupyter notebook and commit that in jovian. I tried to save and upload but did not work.

complete all questions previously its shoe number in [ ]In statement
but after practice 1 its show (*)