From 318534288af1ffdb549fa88aa28a0e86c8c23fa3 Mon Sep 17 00:00:00 2001 From: Thomas Mitchell Date: Fri, 29 Sep 2017 11:48:39 -0400 Subject: [PATCH 1/5] Question 2 for Exercise 6. A guessing game! -Thomas --- GuessNumber | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 GuessNumber diff --git a/GuessNumber b/GuessNumber new file mode 100644 index 0000000..ce18bd0 --- /dev/null +++ b/GuessNumber @@ -0,0 +1,44 @@ +# Importation of packages and navigation to biocomputing directory. + +import numpy +import os +import pandas +os.listdir('.') +os.chdir('/Users/winghomitchell/Intro_Biocom_ND_319_Tutorial6') + +# Line thirteen will print a prompt for the user to read. +# Line fourteen will store the randomly generated number between 1-100 in an variable called "answer" +# Line fifteen will convert guess into an integer and prompt the user to enter a number. + +print('I am thinking of a number between 1 and 100...') +answer = numpy.random.choice(100) +guess = int(input('Guess?')) + +# While loop will iterate so as long as the user's guess is not equal to the randomly generated integer stored in answer. + +while guess != answer: + +# This block of code will execute if the guess is greater than the value stored in the answer variable. +# In the event that the guess is correct, the program will end. + + if int(guess) > int(answer): + print (guess) + print('Lower...') + guess = input('Guess?') + + if int(guess) == int(answer): + print (guess) + print ('Correct!') + +# This block of code will execute if the guess is less than the value stored in the answer variable. +# In the event that the guess is correct, the program will end. + + elif int(guess) < int(answer): + print (guess) + print ('Greater...') + guess = input('Guess?') + + if int(guess) == int(answer): + print (guess) + print ('Correct!') + From a0d620d9d561a67628ecc488d84cc9a9a729ac20 Mon Sep 17 00:00:00 2001 From: Thomas Mitchell Date: Thu, 5 Oct 2017 19:03:59 -0400 Subject: [PATCH 2/5] Added updated version for the guessing game, second part of the sixth exercise - Thomas --- guessinggamev2 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 guessinggamev2 diff --git a/guessinggamev2 b/guessinggamev2 new file mode 100644 index 0000000..72d30a2 --- /dev/null +++ b/guessinggamev2 @@ -0,0 +1,52 @@ +# Importation of packages and navigation to biocomputing directory. + +import numpy +import os +import pandas +os.listdir('.') +os.chdir('/Users/winghomitchell/Intro_Biocom_ND_319_Tutorial6') + +# Line thirteen will print a prompt for the user to read. +# Line fourteen will store the randomly generated number between 1-100 in an variable called "answer" +# Line fifteen will convert guess into an integer and prompt the user to enter a number. + +print('I am thinking of a number between 1 and 100...') +answer = numpy.random.choice(100) +guess = int(input('Guess?')) +count = int(0) + +# While loop will iterate so as long as the user's guess is not equal to the randomly generated integer stored in answer. + +while guess != answer: + +# This block of code will execute if the guess is greater than the value stored in the answer variable. +# In the event that the guess is correct, the program will end. +# This version of the guessing game incorporates a simple counter to track the number of guesses required to arrive at the correct answer. + + if int(guess) > int(answer): + print (guess) + print('Lower...') + guess = input('Guess?') + count = count + 1 + + if int(guess) == int(answer): + print (guess) + print ('Correct!') + print ('You guessed the number in %d guesses!' %(count)) + +# This block of code will execute if the guess is less than the value stored in the answer variable. +# In the event that the guess is correct, the program will end. +# This version of the guessing game incorporates a simple counter to track the number of guesses required to arrive at the correct answer. + + elif int(guess) < int(answer): + print (guess) + print ('Greater...') + guess = input('Guess?') + count = count + 1 + + if int(guess) == int(answer): + print (guess) + print ('Correct!') + print ('You guessed the number in %d guesses!' %(count)) + +# End of script. From 88b1c15d11850d06edaf3fdaa7e3c4a2db44ecb8 Mon Sep 17 00:00:00 2001 From: Thomas Mitchell Date: Thu, 5 Oct 2017 19:07:57 -0400 Subject: [PATCH 3/5] Fixed off-by-one error on added counter. -Thomas --- guessinggamev2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guessinggamev2 b/guessinggamev2 index 72d30a2..11fb1c3 100644 --- a/guessinggamev2 +++ b/guessinggamev2 @@ -13,7 +13,7 @@ os.chdir('/Users/winghomitchell/Intro_Biocom_ND_319_Tutorial6') print('I am thinking of a number between 1 and 100...') answer = numpy.random.choice(100) guess = int(input('Guess?')) -count = int(0) +count = int(1) # While loop will iterate so as long as the user's guess is not equal to the randomly generated integer stored in answer. From f2c99c8d34afbfaced1cf6c446f6ac55e9a72ffb Mon Sep 17 00:00:00 2001 From: Balaji Sampathkumar Date: Thu, 5 Oct 2017 20:53:58 -0400 Subject: [PATCH 4/5] Code for Question 1 - Balaji --- EX_6_Script | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 EX_6_Script diff --git a/EX_6_Script b/EX_6_Script new file mode 100644 index 0000000..c4ff225 --- /dev/null +++ b/EX_6_Script @@ -0,0 +1,28 @@ +import numpy +import os +import matplotlib.pyplot as plt +os.listdir('.') +os.chdir('/Users/sampathkumarbalaji/EX_6/Intro_Biocom_ND_319_Tutorial6') +import pandas +UWvMSU_txt=pandas.read_csv("UWvMSU_1-22-13.txt",delimiter='\t') +#size = UWvMSU_txt.groupby(by=['team']).count() +n_row = UWvMSU_txt.shape[0] +UW_cum_score = 0 +MSU_cum_score = 0 +A=numpy.zeros((n_row-1,3)) +cum_df=pandas.DataFrame(A,columns=['time','UW_cum_score', 'MSU_cum_score']) + +for index in range(0,n_row-1): + + if UWvMSU_txt.team[index] == 'UW': + UW_cum_score += UWvMSU_txt.score[index] + cum_df.UW_cum_score[index] = UW_cum_score + cum_df.MSU_cum_score[index] = MSU_cum_score + cum_df.time[index] = UWvMSU_txt.time[index] + else: + MSU_cum_score += UWvMSU_txt.score[index] + cum_df.MSU_cum_score[index] = MSU_cum_score + cum_df.UW_cum_score[index] = UW_cum_score + cum_df.time[index] = UWvMSU_txt.time[index] + +plt.plot(cum_df.time,cum_df.UW_cum_score,'r-',cum_df.time,cum_df.MSU_cum_score,'g-') From db75ad750242e2fb3d6d4ab85429ae7887b15d45 Mon Sep 17 00:00:00 2001 From: Balaji Sampathkumar Date: Thu, 5 Oct 2017 21:02:34 -0400 Subject: [PATCH 5/5] Code for Question 1 - Balaji --- EX_6_Script | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/EX_6_Script b/EX_6_Script index c4ff225..4e48077 100644 --- a/EX_6_Script +++ b/EX_6_Script @@ -4,14 +4,21 @@ import matplotlib.pyplot as plt os.listdir('.') os.chdir('/Users/sampathkumarbalaji/EX_6/Intro_Biocom_ND_319_Tutorial6') import pandas + +#to parse and read txt file UWvMSU_txt=pandas.read_csv("UWvMSU_1-22-13.txt",delimiter='\t') -#size = UWvMSU_txt.groupby(by=['team']).count() + +#find no. of rows in the txt file n_row = UWvMSU_txt.shape[0] UW_cum_score = 0 MSU_cum_score = 0 + +#create a new data frame to have time and cummlative scores as columns A=numpy.zeros((n_row-1,3)) cum_df=pandas.DataFrame(A,columns=['time','UW_cum_score', 'MSU_cum_score']) +#parse through every row, find team name, accumulate respective cum_score variables + for index in range(0,n_row-1): if UWvMSU_txt.team[index] == 'UW': @@ -25,4 +32,5 @@ for index in range(0,n_row-1): cum_df.UW_cum_score[index] = UW_cum_score cum_df.time[index] = UWvMSU_txt.time[index] +#plot graph time vs cum_scores for both the teams plt.plot(cum_df.time,cum_df.UW_cum_score,'r-',cum_df.time,cum_df.MSU_cum_score,'g-')