# Ricky Fox 1/7/22
# I learned how to upload files in code and append them
# I did have any difficulty on this assignment
#Import file and link
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow -o rainbow.txt
rainbow_file = open("rainbow.txt","r")
rainbow_lines = rainbow_file.readlines()
rainbow_lines.sort()
for color in rainbow_lines:
print(color)
rainbow_file.close()
# Code uses a curl statement
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt
# Code uses the open method and readline method
mean_temp = open("mean_temp.txt","r")
headings = mean_temp.readline()
print(headings)
headings = headings.split(',')
print(headings)
# Code displays city_temp indexes
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()
# Code uses curl method to display random appearing numbers by reading digits
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi -o pi.txt
# Code asks user to enter name and displays message that says "Hi, [name of person]"
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
# Code uses .close and a while loop to display a number using if/else statements
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()