# [ ] import https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow as rainbow.txt
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow -o rainbow.txt
# [ ] Open rainbow.txt in read mode & read as list with .readlines()
rainbow_file = open("rainbow.txt","r")
rainbow_lines = rainbow_file.readlines()
# [ ] sort rainbow_colors list, iterate the list to print each color
rainbow_lines.sort()
for color in rainbow_lines:
print(color)
rainbow_file.close()
# [ ] The Weather: import world_mean_team.csv as mean_temp.txt
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt
# [ ] The Weather: open file, read/print first line, convert line to list (splitting on comma)
mean_temp = open("mean_temp.txt","r")
headings = mean_temp.readline()
print(headings)
headings = headings.split(',')
print(headings)
# [ ] The Weather: use while loop to print city and highest monthly average temp 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()
# [ ] use curl to download https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi as pi.txt
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi -o pi.txt
# [ ] Set up the project files and initial values
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
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()