# Kristika Sedai
# November 8, 2021
# I learned about open and .read() local files in memory, read() a specific number of characters, use .readlines()
# to read data from file as a list of lines, Use .readline() to read data from file a line at a time, Use .strip()
# to remove new line characters,.write() data to a new local file, Use .seek() to set file read or write location.
# I am having trouble with Task 2.
# [ ] 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")
rainbow_colors = rainbow_file.readlines()
# [ ] sort rainbow_colors list, iterate the list to print each color
rainbow_colors.sort()
for color in rainbow_colors:
print(color)
# [ ] The Weather: import world_mean_team.csv as mean_temp.txt
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv
# [ ] 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.read(1)
print(headings)
mean_temp_list = headings.split(",")
print(mean_temp_list)
# [ ] The Weather: use while loop to print city and highest monthly average temp in celsius
city_temp = ""
while city_temp:
city_temp_list = city_temp.split()
break
for city in city_temp:
print(city)
mean_temp.close()
print(mean_temp)
# [ ] 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
# Open pi.tx in read mode,
pi_text = open("pi.txt", "r")
# Get username as input and say "hi"
name = input("enter your name: ")
print("Hi", name + "!")
# Use the length of name for variable called seed
seed = len(name)
# Use .seek() to set te intitial pointer location reading te file.
pi_text.seek(0)
# Create a vatiable digit and assign it the value of reading one character from the file.
digit = pi_text.readline()
# Get guess variable value from users input - enter a single digit guess or "q" to quit.
guess = input("enter a single digit guess or q to quit: ")
# Initialize correct and wrong counter variables to zero
correct = 0
wrong = 0
# Create a while loop that tests that guess is a digit string
while True:
# If digit ( read from pi file) is "." read the next character for digit.
if digit == ".":
pass
# Else if digit is "\n" increment seed and use seed to set the pointer uing .seek().
elif digit == "\n":
seed += 1
seed.seek(0)
# Else see if guess is equal to digit
else:
if guess == digit:
print("correct")
correct += 1
else:
print("incorrect")
wrong += 1
break
# Print correct and wrong values within a message to the user.
print("The statement is", correct)
print("The statement is", wrong)
# Close the pi file
pi_text.close()