# reading from and writing to text files
with open("study.txt", "w") as outputFile:
    text = input("Enter in a line to write to a file: ")
    while (text != "q"):
        outputFile.write(text + "\n")
        text = input("Enter in a line to write to a file: ")
    
with open("study.txt", "r") as inputFile:
    for line in inputFile:
        print(line)
# string formatting
print( "hello {0}".format("Nicole") )
print( "hello {1}".format("Nicole", "Benjie") )
print( "hello {0}, {1}, {2}, and especially {0}!".format("Nicole", "Benjie", "Jordan") )
# reading text files from the internet
import urllib.request
url = urllib.request.urlopen("https://csweb.wooster.edu/hguarnera/cs100/assignments/loremipsum.txt")
content = url.readlines()
for line in content:
    s = line.decode("utf-8")
    print(s)
# list comprehensions
# [2, 4, 6, ..., 100]
def generate_list():
    l = [x*2 for x in range(1,51)]
    l = [x for x in range(2, 101, 2)]
    l = [x for x in range(2, 101) if x % 2 == 0]
    return l
print( generate_list() )