-
Notifications
You must be signed in to change notification settings - Fork 10
chambers-yamasaki submission #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayamasaki2011
wants to merge
6
commits into
lyy005:master
Choose a base branch
from
ayamasaki2011:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70b0a53
AEY: Add file for guessing game script to repo
ayamasaki2011 9ede5c9
AEY: Modify game to generate a random # from 1-100
ayamasaki2011 60db907
AEY: Add while loop to test user input against answer - doesn't work …
ayamasaki2011 483538d
Question 1 JC - completed with no loop
jchambe5 a583b7c
Ensure script takes input as an integer
ayamasaki2011 7bb92bf
Combine scripts into one file: Exercise6.py
ayamasaki2011 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-') | ||
|
|
||
| #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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-') | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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