From af76f7c8461f2471d573f3585bd0293a00e9e452 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:11:53 +0100 Subject: [PATCH 01/25] Create index.html --- subtract_numbers/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 subtract_numbers/index.html diff --git a/subtract_numbers/index.html b/subtract_numbers/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/subtract_numbers/index.html @@ -0,0 +1 @@ + From 6c1a9e82c4df83a420255df5a791749335c731af Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:12:47 +0100 Subject: [PATCH 02/25] Add files via upload --- subtract_numbers/credit.txt | 1 + subtract_numbers/index.html | 16 +++++++++++++++- subtract_numbers/soln.py | 26 ++++++++++++++++++++++++++ subtract_numbers/title.txt | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 subtract_numbers/credit.txt create mode 100644 subtract_numbers/soln.py create mode 100644 subtract_numbers/title.txt diff --git a/subtract_numbers/credit.txt b/subtract_numbers/credit.txt new file mode 100644 index 0000000..b869b75 --- /dev/null +++ b/subtract_numbers/credit.txt @@ -0,0 +1 @@ +The example was solved by Mbaoma Chioma Mary (Section Leader for Section 223) \ No newline at end of file diff --git a/subtract_numbers/index.html b/subtract_numbers/index.html index 8b13789..5a17664 100644 --- a/subtract_numbers/index.html +++ b/subtract_numbers/index.html @@ -1 +1,15 @@ - + + + + + Subtract numbers + + +Write a program in the file subtract_numbers.py that reads two real numbers from +the user and prints the first number minus the second number. You can assume the +user will always enter valid real numbers as input (negative values are fine). Yes, we +know this problem is really similar to a problem we did in class – that’s why this +problem is a sandcastle! + + + \ No newline at end of file diff --git a/subtract_numbers/soln.py b/subtract_numbers/soln.py new file mode 100644 index 0000000..80d76cb --- /dev/null +++ b/subtract_numbers/soln.py @@ -0,0 +1,26 @@ +#subtract numbers +#a python script which accepts two numbers from the user, +#and subtracts the second from the first + +#define the function +def main(): + #accept the first input + #float keyword converts the input to a decimal number for uniformity + first_number = float(input('Kindly enter a number: ')) + + #accept the second input + second_number = float(input('Kindly enter another number: ')) + + #subtract the second input from the first input + result = first_number - second_number + + #i used f string formatting to display the final answer in a format that's more readable + #the variable name holding my answer to the subtraction is put in a curly bracket and placed at the + #position where i want it to be + print(f'The result is {result}') + +#call your function +if __name__ == '__main__': + main() + +#---------------------------------------------------------- \ No newline at end of file diff --git a/subtract_numbers/title.txt b/subtract_numbers/title.txt new file mode 100644 index 0000000..eb2976b --- /dev/null +++ b/subtract_numbers/title.txt @@ -0,0 +1 @@ +The title of this solved example is Subtract numbers and it falls under the Sandcastles problem. From ada0fea1fe8f1f79a985433b11eeb47d4e51d4c9 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:13:25 +0100 Subject: [PATCH 03/25] Delete credit.txt --- subtract_numbers/credit.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 subtract_numbers/credit.txt diff --git a/subtract_numbers/credit.txt b/subtract_numbers/credit.txt deleted file mode 100644 index b869b75..0000000 --- a/subtract_numbers/credit.txt +++ /dev/null @@ -1 +0,0 @@ -The example was solved by Mbaoma Chioma Mary (Section Leader for Section 223) \ No newline at end of file From a2cdaa43fcf04d7e5697dbf271d7bd2058cec32c Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:13:35 +0100 Subject: [PATCH 04/25] Delete index.html --- subtract_numbers/index.html | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 subtract_numbers/index.html diff --git a/subtract_numbers/index.html b/subtract_numbers/index.html deleted file mode 100644 index 5a17664..0000000 --- a/subtract_numbers/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - Subtract numbers - - -Write a program in the file subtract_numbers.py that reads two real numbers from -the user and prints the first number minus the second number. You can assume the -user will always enter valid real numbers as input (negative values are fine). Yes, we -know this problem is really similar to a problem we did in class – that’s why this -problem is a sandcastle! - - - \ No newline at end of file From 984cb6ca43220220af2117b57a44c1a5b2bf884c Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:13:46 +0100 Subject: [PATCH 05/25] Delete soln.py --- subtract_numbers/soln.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 subtract_numbers/soln.py diff --git a/subtract_numbers/soln.py b/subtract_numbers/soln.py deleted file mode 100644 index 80d76cb..0000000 --- a/subtract_numbers/soln.py +++ /dev/null @@ -1,26 +0,0 @@ -#subtract numbers -#a python script which accepts two numbers from the user, -#and subtracts the second from the first - -#define the function -def main(): - #accept the first input - #float keyword converts the input to a decimal number for uniformity - first_number = float(input('Kindly enter a number: ')) - - #accept the second input - second_number = float(input('Kindly enter another number: ')) - - #subtract the second input from the first input - result = first_number - second_number - - #i used f string formatting to display the final answer in a format that's more readable - #the variable name holding my answer to the subtraction is put in a curly bracket and placed at the - #position where i want it to be - print(f'The result is {result}') - -#call your function -if __name__ == '__main__': - main() - -#---------------------------------------------------------- \ No newline at end of file From 4d93ebb81ce84b4d9df63c1ebb9bd04ead054bf2 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:13:56 +0100 Subject: [PATCH 06/25] Delete title.txt --- subtract_numbers/title.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 subtract_numbers/title.txt diff --git a/subtract_numbers/title.txt b/subtract_numbers/title.txt deleted file mode 100644 index eb2976b..0000000 --- a/subtract_numbers/title.txt +++ /dev/null @@ -1 +0,0 @@ -The title of this solved example is Subtract numbers and it falls under the Sandcastles problem. From 8f0c8b2abe32a8b5886c803ed2a9113b2782a06b Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:14:37 +0100 Subject: [PATCH 07/25] Create index.html --- examples/subtract_numbers/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/subtract_numbers/index.html diff --git a/examples/subtract_numbers/index.html b/examples/subtract_numbers/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/subtract_numbers/index.html @@ -0,0 +1 @@ + From d8292f6c7c5b387aab07256c5260776df7471dad Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Fri, 24 Apr 2020 20:15:05 +0100 Subject: [PATCH 08/25] Add files via upload --- examples/subtract_numbers/credit.txt | 1 + examples/subtract_numbers/index.html | 16 +++++++++++++++- examples/subtract_numbers/soln.py | 26 ++++++++++++++++++++++++++ examples/subtract_numbers/title.txt | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 examples/subtract_numbers/credit.txt create mode 100644 examples/subtract_numbers/soln.py create mode 100644 examples/subtract_numbers/title.txt diff --git a/examples/subtract_numbers/credit.txt b/examples/subtract_numbers/credit.txt new file mode 100644 index 0000000..b869b75 --- /dev/null +++ b/examples/subtract_numbers/credit.txt @@ -0,0 +1 @@ +The example was solved by Mbaoma Chioma Mary (Section Leader for Section 223) \ No newline at end of file diff --git a/examples/subtract_numbers/index.html b/examples/subtract_numbers/index.html index 8b13789..5a17664 100644 --- a/examples/subtract_numbers/index.html +++ b/examples/subtract_numbers/index.html @@ -1 +1,15 @@ - + + + + + Subtract numbers + + +Write a program in the file subtract_numbers.py that reads two real numbers from +the user and prints the first number minus the second number. You can assume the +user will always enter valid real numbers as input (negative values are fine). Yes, we +know this problem is really similar to a problem we did in class – that’s why this +problem is a sandcastle! + + + \ No newline at end of file diff --git a/examples/subtract_numbers/soln.py b/examples/subtract_numbers/soln.py new file mode 100644 index 0000000..80d76cb --- /dev/null +++ b/examples/subtract_numbers/soln.py @@ -0,0 +1,26 @@ +#subtract numbers +#a python script which accepts two numbers from the user, +#and subtracts the second from the first + +#define the function +def main(): + #accept the first input + #float keyword converts the input to a decimal number for uniformity + first_number = float(input('Kindly enter a number: ')) + + #accept the second input + second_number = float(input('Kindly enter another number: ')) + + #subtract the second input from the first input + result = first_number - second_number + + #i used f string formatting to display the final answer in a format that's more readable + #the variable name holding my answer to the subtraction is put in a curly bracket and placed at the + #position where i want it to be + print(f'The result is {result}') + +#call your function +if __name__ == '__main__': + main() + +#---------------------------------------------------------- \ No newline at end of file diff --git a/examples/subtract_numbers/title.txt b/examples/subtract_numbers/title.txt new file mode 100644 index 0000000..eb2976b --- /dev/null +++ b/examples/subtract_numbers/title.txt @@ -0,0 +1 @@ +The title of this solved example is Subtract numbers and it falls under the Sandcastles problem. From af82a656599ae9a5e1b4092c3d75ea9cb54c819b Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:34:21 +0100 Subject: [PATCH 09/25] Update index.html Added a sample run of the program --- examples/subtract_numbers/index.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/subtract_numbers/index.html b/examples/subtract_numbers/index.html index 5a17664..485521f 100644 --- a/examples/subtract_numbers/index.html +++ b/examples/subtract_numbers/index.html @@ -9,7 +9,13 @@ the user and prints the first number minus the second number. You can assume the user will always enter valid real numbers as input (negative values are fine). Yes, we know this problem is really similar to a problem we did in class – that’s why this -problem is a sandcastle! +problem is a sandcastle!
+A sample run of the program is shown below:
+This program subtracts one number from another.
+Enter first number: 5.5
+Enter second number: 2.1
+The result is 3.4
+ - \ No newline at end of file + From 71d21f30ea74d37845215b8c5dd92356389aa720 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:37:51 +0100 Subject: [PATCH 10/25] Update soln.py Edited the program for better readability --- examples/subtract_numbers/soln.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/subtract_numbers/soln.py b/examples/subtract_numbers/soln.py index 80d76cb..1fe17c9 100644 --- a/examples/subtract_numbers/soln.py +++ b/examples/subtract_numbers/soln.py @@ -4,12 +4,15 @@ #define the function def main(): + #print the title of the program + print('This program subtracts one number from another.') + #accept the first input #float keyword converts the input to a decimal number for uniformity - first_number = float(input('Kindly enter a number: ')) + first_number = float(input('Enter first number: ')) #accept the second input - second_number = float(input('Kindly enter another number: ')) + second_number = float(input('Enter second number: ')) #subtract the second input from the first input result = first_number - second_number @@ -23,4 +26,4 @@ def main(): if __name__ == '__main__': main() -#---------------------------------------------------------- \ No newline at end of file +#---------------------------------------------------------- From 9300c93787f951d9384eadfa056ecbb82e1e370c Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:45:29 +0100 Subject: [PATCH 11/25] Create index.html --- examples/random_numbers/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/random_numbers/index.html diff --git a/examples/random_numbers/index.html b/examples/random_numbers/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/random_numbers/index.html @@ -0,0 +1 @@ + From c4f71f5cc0b752e2e9b0d3799ea3a860933609eb Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:48:32 +0100 Subject: [PATCH 12/25] Add files via upload --- examples/random_numbers/credit.txt | 1 + examples/random_numbers/index.html | 29 ++++++++++++++++++++++++++++- examples/random_numbers/soln.py | 30 ++++++++++++++++++++++++++++++ examples/random_numbers/title.txt | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 examples/random_numbers/credit.txt create mode 100644 examples/random_numbers/soln.py create mode 100644 examples/random_numbers/title.txt diff --git a/examples/random_numbers/credit.txt b/examples/random_numbers/credit.txt new file mode 100644 index 0000000..168fb10 --- /dev/null +++ b/examples/random_numbers/credit.txt @@ -0,0 +1 @@ +This solved example was written by Mbaoma Chioma Mary (Section Leader of Section 223) \ No newline at end of file diff --git a/examples/random_numbers/index.html b/examples/random_numbers/index.html index 8b13789..33bdc02 100644 --- a/examples/random_numbers/index.html +++ b/examples/random_numbers/index.html @@ -1 +1,28 @@ - + + + + + Random numbers + + +Write a program in the file random_numbers.py that prints 10 random integers (each +random integer should have a value between 0 and 100, inclusive). Your program +should use a constant named NUM_RANDOM, which determines the number of random +numbers to print (with a value of 10). It should also use constants named MIN_RANDOM +and MAX_RANDOM to determine the minimal and maximal values of the random numbers +generated (with respective values 0 and 100). To generate random numbers, you should +use the function random.randint() from Python’s random library.
+Example:
+35
+10
+45
+59
+45
+100
+8
+31
+48
+6
+It's alright if your code does not generate the exact numbers above. + + \ No newline at end of file diff --git a/examples/random_numbers/soln.py b/examples/random_numbers/soln.py new file mode 100644 index 0000000..db7d570 --- /dev/null +++ b/examples/random_numbers/soln.py @@ -0,0 +1,30 @@ +#we want to print 10 random numbers within the range of 0 and 100 (100 inclusive) +#we import the random library because we are printing a list of RANDOM numbers +import random + +#define your function +def main(): + #set the length of our proposed list of numbers + num_random = 10 + + #we set our starting value + min_random = 0 + + #we set our stopping value + max_random = 100 + + #we use a 'for' loop becuase we know the range/size of our list (i.e. 10) + #range is an inbuilt function in python that is used to specify the length of a list + #or number of iterations a funtion should undertake + for i in range(num_random): + + #the variable name 'random_num' contains the random integer to be generated by our script + #random.randint has this format random.randint(start, end) + random_num = random.randint(min_random, max_random) + + #we get a list of 10 numbers because we combined the random.randint function with a for loop + print(random_num) + +#call the function +if __name__ == '__main__': + main() diff --git a/examples/random_numbers/title.txt b/examples/random_numbers/title.txt new file mode 100644 index 0000000..2512207 --- /dev/null +++ b/examples/random_numbers/title.txt @@ -0,0 +1 @@ +The title of this solved example is Random numbers and it falls under the Sandcastles problem. From a17c8b83daaa02e7b57abe0b6f38f3e96b2e89f7 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:56:49 +0100 Subject: [PATCH 13/25] Create index.html --- examples/liftoff/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/liftoff/index.html diff --git a/examples/liftoff/index.html b/examples/liftoff/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/liftoff/index.html @@ -0,0 +1 @@ + From 8eb70363e42b55c1adb998e90b33d1a4152ee8f5 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:58:20 +0100 Subject: [PATCH 14/25] Add files via upload Solved example of the liftoff question, a sub question under the Sandcastles problem --- examples/liftoff/credit.txt | 1 + examples/liftoff/index.html | 24 +++++++++++++++++++++++- examples/liftoff/soln.py | 26 ++++++++++++++++++++++++++ examples/liftoff/title.txt | 1 + 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/liftoff/credit.txt create mode 100644 examples/liftoff/soln.py create mode 100644 examples/liftoff/title.txt diff --git a/examples/liftoff/credit.txt b/examples/liftoff/credit.txt new file mode 100644 index 0000000..168fb10 --- /dev/null +++ b/examples/liftoff/credit.txt @@ -0,0 +1 @@ +This solved example was written by Mbaoma Chioma Mary (Section Leader of Section 223) \ No newline at end of file diff --git a/examples/liftoff/index.html b/examples/liftoff/index.html index 8b13789..8d028fd 100644 --- a/examples/liftoff/index.html +++ b/examples/liftoff/index.html @@ -1 +1,23 @@ - + + + + + Liftoff + + +Write a program in the file liftoff.py that prints out the calls for a spaceship that is +about to launch. Countdown the numbers from 10 to 1 and then write “Liftoff!” Your +program should include a for loop using range. A sample run of the program is below.
+10
+9
+8
+7
+6
+5
+4
+3
+2
+1
+Liftoff! + + \ No newline at end of file diff --git a/examples/liftoff/soln.py b/examples/liftoff/soln.py new file mode 100644 index 0000000..c8ef954 --- /dev/null +++ b/examples/liftoff/soln.py @@ -0,0 +1,26 @@ +#a program that works like a countdown call +#the countdown runs from 10 -1 and then prints 'Liftoff' + +#define your function +def main(): + + #we use a for loop and the range funstion which has this format + #range(start, stop, step) + #start - starting value + #stop - stopping value + #step - format of printing the generated numbers + #we set the step value to a negative index so the countdown starts printing from the last + #number in the range (10) and stops at the first number (1) + for num in range(10,0,-1): + + #we print out the 'num' values in the range + print(num) + + #we print 'LIFTOFF!' outside of the loop so it appears at the end of the countdown and not + #inside the countdown sequence + print('Liftoff!') + +#call your function +if __name__ == '__main__': + main() + diff --git a/examples/liftoff/title.txt b/examples/liftoff/title.txt new file mode 100644 index 0000000..59da9d8 --- /dev/null +++ b/examples/liftoff/title.txt @@ -0,0 +1 @@ +The title of this solved example is Liftoff and it falls under the Sandcastles problem (Python solution) From d7f33f1918c285599b3496a446b9ad487f1d9197 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 05:22:10 +0100 Subject: [PATCH 15/25] Create index.html --- examples/Khan Sole Academy/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/Khan Sole Academy/index.html diff --git a/examples/Khan Sole Academy/index.html b/examples/Khan Sole Academy/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/Khan Sole Academy/index.html @@ -0,0 +1 @@ + From fa1296d31138a23df259e3df5b2e77c6c7486c44 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 25 Apr 2020 05:23:44 +0100 Subject: [PATCH 16/25] Add files via upload Solved example for Khan Sole Academy question --- examples/Khan Sole Academy/credit.txt | 1 + examples/Khan Sole Academy/index.html | 67 ++++++++++++++++++++++++++- examples/Khan Sole Academy/soln.py | 59 +++++++++++++++++++++++ examples/Khan Sole Academy/title.txt | 1 + 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 examples/Khan Sole Academy/credit.txt create mode 100644 examples/Khan Sole Academy/soln.py create mode 100644 examples/Khan Sole Academy/title.txt diff --git a/examples/Khan Sole Academy/credit.txt b/examples/Khan Sole Academy/credit.txt new file mode 100644 index 0000000..168fb10 --- /dev/null +++ b/examples/Khan Sole Academy/credit.txt @@ -0,0 +1 @@ +This solved example was written by Mbaoma Chioma Mary (Section Leader of Section 223) \ No newline at end of file diff --git a/examples/Khan Sole Academy/index.html b/examples/Khan Sole Academy/index.html index 8b13789..c561e16 100644 --- a/examples/Khan Sole Academy/index.html +++ b/examples/Khan Sole Academy/index.html @@ -1 +1,66 @@ - + + + + + Khan Sole Academy + + +Now that you’ve seen how programming can help us in a number of different areas, it’s +time for you to implement Khan-sole Academy—a program that helps other people learn! +In this problem, you’ll write a program in the file khansole_academy.py that randomly +generates simple addition problems for the user, reads in the answer from the user, and then +checks to see if they got it right or wrong, until the user appears to have mastered the +material. Note that “console” is another name for “terminal” :-).
+More specifically, your program should be able to generate simple addition problems that +involve adding two 2-digit integers (i.e., the numbers 10 through 99). The user should be +asked for an answer to each problem. Your program should determine if the answer was +correct or not, and give the user an appropriate message to let them know. Your program +should keep giving the user problems until the user has gotten 3 problems correct in a row. +
+(Note: the number of problems the user needs to get correctly in a row to complete the +program is just one example of a good place to specify a constant in your program).
+A sample run of the program is shown below (user input is in italics.) +
+ +Congratulations! You mastered addition.
+As a side note, one of the earliest programs Mehran wrote (with his friend Matthew) when +he was first learning how to program was very similar to Khan-Sole Academy and it was +called “M&M’s Math Puzzles”. It was written in a language named BASIC, on a computer +that had 4K of memory (that’s 4 Kilobytes) and used cassette tapes (the same kind used for +music in the 1970’s) to store information. Yeah, Mehran is old. + + + + \ No newline at end of file diff --git a/examples/Khan Sole Academy/soln.py b/examples/Khan Sole Academy/soln.py new file mode 100644 index 0000000..39c286e --- /dev/null +++ b/examples/Khan Sole Academy/soln.py @@ -0,0 +1,59 @@ +# a python program that randomly generates simple addition problems for the user, +# reads in the answer from the user, +# and then checks to see if they got it right or wrong, +# until the user appears to have mastered the material. + +#import the random library +import random + +#define your function +def main(): + + #we set the number of iterations to 0 as our starting value + iteration = 0 + + #we use a while loop so the keeps running as long as the user defined conditions are true + while True: + + #since we want the program to end after 3 correct consecutive answers, + #we state this condition in an 'if' statement + if iteration == 3: + print('Congratulations! You mastered addition.') + + #'break' keyword breaks out of the loop (ends the program) + break + + #if the 'if' block above is wrong, the 'else' code block would run + else: + num_one = random.randint(10, 99) + num_two = random.randint(10, 99) + result = num_one + num_two + + #we use the f formatting to set values of the variable names in curly brackets at + #the appropriate positions + print(f'What is {num_one} + {num_two}?') + + #we enable the user type in their answers and we convert it to a float using the + #'float' keyword + answer = float(input('Your answer: ')) + + #we define conditions to test the correctness of the user's input (answer) + if answer == result: + + #we increase the value of our iteration (we increase the starting value by 1) + iteration += 1 + + #the use of '/' is called escaping. It is used to inform the interpreter that, + #the character is part of a string + print(f'Correct! You\'ve gotten {iteration} correct in a row.') + + else: + print(f'Incorrect. The expected answer is {result}.') + + #the interation value is reduced by one, so the iteration starts counting all over from 1, + #when the if block above is true + iteration -= iteration + +#call your function +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/examples/Khan Sole Academy/title.txt b/examples/Khan Sole Academy/title.txt new file mode 100644 index 0000000..dcca7f1 --- /dev/null +++ b/examples/Khan Sole Academy/title.txt @@ -0,0 +1 @@ +The title of this solved example is Khan Sole Academy From 083e553eed4261bc758b42cf5461fc9c8b449573 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 2 May 2020 17:31:58 +0100 Subject: [PATCH 17/25] Create index.html --- examples/stroop/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/stroop/index.html diff --git a/examples/stroop/index.html b/examples/stroop/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/stroop/index.html @@ -0,0 +1 @@ + From e6c38ab85b00ced642e78fed1a8622e4b57c3bab Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Sat, 2 May 2020 17:34:27 +0100 Subject: [PATCH 18/25] Stroop test worked example explaining the first test case of the Stroop test --- examples/stroop/credit.txt | 1 + examples/stroop/index.html | 29 +++++++++++++++++++- examples/stroop/soln.py | 54 ++++++++++++++++++++++++++++++++++++++ examples/stroop/title.txt | 1 + 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 examples/stroop/credit.txt create mode 100644 examples/stroop/soln.py create mode 100644 examples/stroop/title.txt diff --git a/examples/stroop/credit.txt b/examples/stroop/credit.txt new file mode 100644 index 0000000..08ac559 --- /dev/null +++ b/examples/stroop/credit.txt @@ -0,0 +1 @@ +This worked example was solved by Mbaoma Chioma Mary, section 223 leader \ No newline at end of file diff --git a/examples/stroop/index.html b/examples/stroop/index.html index 8b13789..47e181f 100644 --- a/examples/stroop/index.html +++ b/examples/stroop/index.html @@ -1 +1,28 @@ - + + + + + Stroop + + +In psychology, the Stroop effect is a demonstration of cognitive interference where a delay in the reaction time of a task occurs due to a mismatch +in stimuli. The corresponding paper is one of the most cited in the history of Psychology. In this section we are going to implement a working version +of a Stroop test.
+Our stroop test has two phases:
+The first phase is the “control phase”. The user is shown color names written in the same font-color.
+Each time the user has to write the name of the color.
+Count how many times they type the name of the color correctly in 10 seconds
+Here are a few examples:
+

pink

+What color ink is the word written in? pink + +

red

+What color ink is the word written in? red + +

blue

+What color ink is the word written in? green
+Correct answer was blue. + + + + \ No newline at end of file diff --git a/examples/stroop/soln.py b/examples/stroop/soln.py new file mode 100644 index 0000000..cd165ac --- /dev/null +++ b/examples/stroop/soln.py @@ -0,0 +1,54 @@ +import random +import time +from colorama import init +from termcolor import colored +init(autoreset=True) + + +def main(): + #call the print_intro funcion + print_intro() + + #assign the random_color_name functin to a variable + color_name = random_color_name() + print(' ') + #call the print_in_color function and set the color_name to match the color of ink the color name would be printed in + #e.g if color_name is 'green', print the font 'green' in green ink + print_in_color(color_name , font_color= color_name) + response = input('What color ink is the word written in? ') + if response != color_name: + print('Correct answer was: ' + color_name) + return response == color_name + + +def print_intro(): + ''' + Function: print intro + Prints a simple welcome message + ''' + print('This is the Stroop test! Name the font-color used:') + #print_in_color('text', 'color') + print_in_color('red', 'red') + print_in_color('blue', 'blue') + print_in_color('pink', 'pink') + print_in_color('green', 'green') + +def random_color_name(): + ''' + Function: random color + Returns a string (either red, blue, pink or green) with equal likelihood + ''' + return random.choice(['red', 'blue', 'pink', 'green']) + +def print_in_color(text, font_color): + ''' + Function: print in color + Just like "print" but this time, you can specify the font-color + ''' + if font_color == 'pink': # magenta is a lot to type... + font_color = 'magenta' #another way of saying if the font color is pink, print the fonts in magenta ink + print(colored(text, font_color, attrs=['bold'])) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/examples/stroop/title.txt b/examples/stroop/title.txt new file mode 100644 index 0000000..ab931f9 --- /dev/null +++ b/examples/stroop/title.txt @@ -0,0 +1 @@ +The title of this worked example is stroop \ No newline at end of file From 05e99374006d85ea3725e7c4a2a382feba9c1e8f Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:02:07 +0100 Subject: [PATCH 19/25] solved example for index game problem --- examples/index-game/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/index-game/index.html diff --git a/examples/index-game/index.html b/examples/index-game/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/index-game/index.html @@ -0,0 +1 @@ + From c952a67bffb3d9f3b700b75b7b310e6102e639de Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:03:58 +0100 Subject: [PATCH 20/25] Add files via upload --- examples/index-game/final-project.py | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/index-game/final-project.py diff --git a/examples/index-game/final-project.py b/examples/index-game/final-project.py new file mode 100644 index 0000000..0d35c69 --- /dev/null +++ b/examples/index-game/final-project.py @@ -0,0 +1,48 @@ +import random + +def main(): + #we set up a list of items + names = ['Julie', 'Mehran', 'Simba', 'Ayesha', 'Karel'] + + #.append is used to add an item to the end of a list + names.append('Omar') + + #we use a for loop to iterate through the list and print out individual members of the list + for name in names: + print(name) + + #len is used to get the length of a list + #i.e number of items in the list + length_of_list = len(names) + + #index of a list starts its count from 0 + max_index = length_of_list - 1 + + #f formats are used to print out strings + #te=he value in brace brakets can be any data type + print(f' the list has {length_of_list} items') + print(f'the list has a maximum index of {max_index}') + + #we set the variable name 'index' to a random value provided the value is a valid index + index = random.randint(0,max_index) + + #item_index prints the item at the random index above + item_index = names[index] + print(f'a random index is {index}') + print(f'an item at a randomly selected index is {item_index}') + + #who is in what index + print(names) + prompt = input(f'Who is at index {index}?: ') + correct_answer = names[index] + + #it is possible to assign two or more variable names to two or more values + #the .lower is used to set the values of prompt and correct_answer to lowercase to ensure that + #no matter the format the user enters the values, the interpreter converts it to lowercase + prompt , correct_answer = prompt.lower() , correct_answer.lower() + if prompt == correct_answer: + print('Correct!') + else: + print(f'Correct answer is, {correct_answer}') +if __name__ == '__main__': + main() \ No newline at end of file From 658e17b734993518a04301fb7e538914fc1c799d Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:05:00 +0100 Subject: [PATCH 21/25] Rename final-project.py to soln.py --- examples/index-game/{final-project.py => soln.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/index-game/{final-project.py => soln.py} (96%) diff --git a/examples/index-game/final-project.py b/examples/index-game/soln.py similarity index 96% rename from examples/index-game/final-project.py rename to examples/index-game/soln.py index 0d35c69..cb6b37c 100644 --- a/examples/index-game/final-project.py +++ b/examples/index-game/soln.py @@ -45,4 +45,4 @@ def main(): else: print(f'Correct answer is, {correct_answer}') if __name__ == '__main__': - main() \ No newline at end of file + main() From 6086607f791699b39b580895ce5736b6089d85e0 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:06:39 +0100 Subject: [PATCH 22/25] Add files via upload --- examples/index-game/index5.html | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 examples/index-game/index5.html diff --git a/examples/index-game/index5.html b/examples/index-game/index5.html new file mode 100644 index 0000000..ca13ca4 --- /dev/null +++ b/examples/index-game/index5.html @@ -0,0 +1,65 @@ + + + + + The Index Game + + + + We are going to take the first step into data science. You will learn about lists and files!
+

1. The Index Game

+As a warmup, read this code and play the game a few times. Use this mental model of the list:
+ + + + + + + + +
+ + + + + + + +
+
Value 'Julie' 'Mehran' 'Simba' 'Ayesha' 'Karel'
Index 0 1 2 3 4

+ +

def main():
+

# 1. Understand how to create a list and add values
+ # A list is an ordered collection of values
+ names = ['Julie', 'Mehran', 'Simba', 'Ayesha']
+ names.append( 'Karel' )
+ # 2. Understand how to loop over a list
+ # this prints the list to the screen one value at a time
+ for value in names:
+ print(value)
+ # 3. Understand how to look up the length of a list
+ # use randint to select a valid "index"
+ max_index = len(names) - 1
+ index = random.randint(0, max_index)
+ # 4. Understand how to get a value by its index
+ # get the item at the chosen index
+ correct_answer = names[index]
+ # This is just like in Khansole Academy...
+ # prompt the user for an answer, check if it is correct
+ prompt = 'who is in index...' + str(index)+ '? '
+ answer = input(prompt)
+ if answer == correct_answer:
+ print('Good job')
+ else:
+ print('Correct answer was' , correct_answer)


+ + + \ No newline at end of file From 250b47d4a670f110a6656b8b500c0388a3b3e561 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:07:53 +0100 Subject: [PATCH 23/25] Delete index.html --- examples/index-game/index.html | 1 - 1 file changed, 1 deletion(-) delete mode 100644 examples/index-game/index.html diff --git a/examples/index-game/index.html b/examples/index-game/index.html deleted file mode 100644 index 8b13789..0000000 --- a/examples/index-game/index.html +++ /dev/null @@ -1 +0,0 @@ - From e006aada3372349a20d72c859370a1d3abe96d85 Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:08:54 +0100 Subject: [PATCH 24/25] renamed 'html5' on local system to 'index.html' --- examples/index-game/{index5.html => index.html} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/index-game/{index5.html => index.html} (97%) diff --git a/examples/index-game/index5.html b/examples/index-game/index.html similarity index 97% rename from examples/index-game/index5.html rename to examples/index-game/index.html index ca13ca4..1161a61 100644 --- a/examples/index-game/index5.html +++ b/examples/index-game/index.html @@ -62,4 +62,4 @@

1. The Index Game

print('Correct answer was' , correct_answer)


- \ No newline at end of file + From 546c64b153cea54a02da9b9d9582a557f38ea10f Mon Sep 17 00:00:00 2001 From: "Mbaoma Chioma (Omarrr)" <49791498+Mbaoma@users.noreply.github.com> Date: Tue, 12 May 2020 10:11:03 +0100 Subject: [PATCH 25/25] Add files via upload --- examples/index-game/credit.txt | 1 + examples/index-game/title.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 examples/index-game/credit.txt create mode 100644 examples/index-game/title.txt diff --git a/examples/index-game/credit.txt b/examples/index-game/credit.txt new file mode 100644 index 0000000..b869b75 --- /dev/null +++ b/examples/index-game/credit.txt @@ -0,0 +1 @@ +The example was solved by Mbaoma Chioma Mary (Section Leader for Section 223) \ No newline at end of file diff --git a/examples/index-game/title.txt b/examples/index-game/title.txt new file mode 100644 index 0000000..2217ad8 --- /dev/null +++ b/examples/index-game/title.txt @@ -0,0 +1 @@ +The title of this solved example is Index Game (Python solution)