Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Exercise6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Part 1
#load file
import pandas
file=pandas.read_csv("UWvMSU_1-22-13.txt",header=0,sep="\t")
#making a UW only table
UWscore=file[file.team == 'UW']
#making a MSU only table
MSUscore=file[file.team == 'MSU']
#cumulative sum of scores
new = UWscore['cum_sum'] = UWscore.score.cumsum()
new2 = MSUscore['cum_sum'] = MSUscore.score.cumsum()
import matplotlib.pyplot as plt
plt.plot(UWscore['time'], UWscore['cum_sum'], 'r-', MSUscore['time'],
MSUscore['cum_sum'], 'g-')

@lyy005 lyy005 Oct 12, 2017

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. The graph looks good and the way you use to calculate the cumulative sum is great.

The only problem is that when you plot two lists, the graph will make a straight line to connect two data points. The score of the intermediate score may not be correct

#Part 2
#"Guess my Number" game
#Takes user input of a number from 1-100 and compares it to a randomly-generated value
#Tells user if their guess is higher or lower than the correct answer
#User may keep guessing until they get the correct value

import numpy
range=numpy.arange(1,101) #define array of possible number choices to exclude 0 and include 100
answer=numpy.random.choice(range) #generate a random number guess
guess=0 #clear variable from the last game

print("I'm thinking of a number from 1-100. Take a guess!") #Initiate game
guess=int(input(prompt="Your guess:")) #Store a guess from the user

while guess != answer: #Test if the user input is right
if guess < answer: #If not, test whether the guess is lower or higher than the answer
print guess, "is lower than my number."
guess=int(input(prompt="Guess again:"))
elif guess > answer:
print guess, "is higher than my number."
guess=int(input(prompt="Guess again:"))

print guess, "is the right answer!" #If the answer is correct, let the user know

23 changes: 23 additions & 0 deletions NumberGuess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#"Guess my Number" game
#Takes user input of a number from 1-100 and compares it to a randomly-generated value
#Tells user if their guess is higher or lower than the correct answer
#User may keep guessing until they get the correct value

import numpy
range=numpy.arange(1,101) #define array of possible number choices to exclude 0 and include 100
answer=numpy.random.choice(range) #generate a random number guess
guess=0 #clear variable from the last game

print("I'm thinking of a number from 1-100. Take a guess!") #Initiate game
guess=int(input(prompt="Your guess:")) #Store a guess from the user

while guess != answer: #Test if the user input is right
if guess < answer: #If not, test whether the guess is lower or higher than the answer

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good. You may want to put "guess=int(input(prompt="Your guess:"))" within the while loop so that you don't need to run the code after the first input

print guess, "is lower than my number."
guess=int(input(prompt="Guess again:"))
elif guess > answer:
print guess, "is higher than my number."
guess=int(input(prompt="Guess again:"))

print guess, "is the right answer!" #If the answer is correct, let the user know

18 changes: 18 additions & 0 deletions question1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#load file
import pandas
file=pandas.read_csv("UWvMSU_1-22-13.txt",header=0,sep="\t")
#making a UW only table
UWscore=file[file.team == 'UW']
#making a MSU only table
MSUscore=file[file.team == 'MSU']
#cumulative sum of scores
new = UWscore['cum_sum'] = UWscore.score.cumsum()
new2 = MSUscore['cum_sum'] = MSUscore.score.cumsum()
import matplotlib.pyplot as plt
plt.plot(UWscore['time'], UWscore['cum_sum'], 'r-', MSUscore['time'], MSUscore['cum_sum'], 'g-')