#Helina Hailu
#January 8, 2022
#I reviewed things like .read(), .readlines(), .readline, .strip(), .write(), and .seek().
#I had no difficulty completing this lab assignment.
#Using !curl to import the web address and renaming it rainbow.txt using -o
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow -o rainbow.txt
#Using open() to open the file and using .readlines to read the file
rainbow_file = open("rainbow.txt","r")
rainbow_lines = rainbow_file.readlines()
#Using .sort() to sort it alphabetically, for in to print it on separate lines, and closing the file
rainbow_lines.sort()
for color in rainbow_lines:
print(color)
rainbow_file.close()
#Using !curl to import the web address and renaming it mean_temp.txt using -o
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt
#Opening mean_temp and reading it, then printing the original output. Then using .split() to split on every comma and printing that.
mean_temp = open("mean_temp.txt","r")
headings = mean_temp.readline()
print(headings)
headings = headings.split(',')
print(headings)
#Using while, split(´,´), and .readline() to print the cities and thier temperature in celsius
city_temp = mean_temp.readline()
while city_temp:
city_list = city_temp.split(',')
print(city_list[0] + ": " + city_list[2])
city_temp = mean_temp.readline()
mean_temp.close()
#Using !curl to import the web address and -o to rename it pi.txt
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi -o pi.txt
# Using len, print, and input to print "Hi (input) !"
pi_file = open("pi.txt","r")
name = input("What is your name?")
print("Hi, " + name.capitalize() + "!")
seed = len(name)
pi_file.seek(seed)
digit = pi_file.read(1)
guess = input('Enter a single digit guess or "q" to quit: ')
correct = 0
wrong = 0
#Using while, if elif else to create a function that tells you if you guessed the right number
while guess.isdigit():
if digit == ".":
digit = pi_file.read(1)
elif digit == "\n":
seed += 1
pi_file.seek(seed)
digit = pi_file.read(1)
else:
if guess == digit:
print(guess,"is correct")
correct += 1
else:
print(guess, "is incorrect")
wrong += 1
guess = input("Enter another digit guess or \"q\": ")
print("\nCorrect:",correct,"\nIncorrect:",wrong)
pi_file.close()