Skip to content

Instantly share code, notes, and snippets.

View IvanFrecia's full-sized avatar

Ivan Frecia IvanFrecia

  • Landtail
  • Buenos Aires, Argentina
View GitHub Profile
@mayankdawar
mayankdawar / CountLines.py
Created March 16, 2020 10:34
Write code to find out how many lines are in the file emotion_words.txt as shown above. Save this value to the variable num_lines. Do not use the len method.
#Write code to find out how many lines are in the file emotion_words.txt as shown above. Save this value to the variable num_lines. Do not use the len method.
file = open("emotion_word.txt","r")
count = 0
for aline in file.readlines():
count += 1
num_lines = count
@mayankdawar
mayankdawar / reversedPalindrome.py
Created February 22, 2020 20:50
A palindrome is a phrase that, if reversed, would read the exact same. Write code that checks if p_phrase is a palindrome by reversing it and then checking if the reversed version is equal to the original. Assign the reversed version of p_phrase to the variable r_phrase so that we can check your work.
p_phrase = "was it a car or a cat I saw"
r_phrase = p_phrase[::-1]
@mayankdawar
mayankdawar / ConditionalAcronym.py
Created February 22, 2020 20:34
Write code that uses the string stored in sent and creates an acronym which is assigned to the variable acro. The first two letters of each word should be used, each letter in the acronym should be a capital letter, and each element of the acronym should be separated by a “. ” (dot and space). Words that should not be included in the acronym are…
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The']
sent = "The water earth and air are vital"
acro = ""
lst = sent.split()
for i in lst:
if i in stopwords:
lst.remove(i)
for j in lst:
# 1. The textfile, travel_plans.txt, contains the summer travel plans for someone with some commentary.
# Find the total number of characters in the file and save to the variable num.
fileref = open("travel_plans.txt","r")
num = 0
for i in fileref:
num += len(i)
fileref.close()
# 2. We have provided a file called emotion_words.txt that contains lines of words that describe emotions.