From 43089050f9adae8d33bd8a2df2bad5e05fc50a4d Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Wed, 1 Nov 2017 09:00:15 -0500 Subject: [PATCH 01/14] Finished worksheet for chapter 1 --- Worksheets/worksheet_01.txt | 71 ++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..85b33fb 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,23 +6,29 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. - + print("Jared Rhodes") 2. How do you enter a comment in a program? - + You use the # character to create a comment that won't be read by the program 3. What do the following lines of code output? ALSO: Why do they give a different answer? - print(2 / 3) - print(2 // 3) + print(2 / 3) prints the sum of 2 divided by 3 + print(2 // 3) prints 2 / 3 + + These do different things because a single / is used as a math operator so in order to print a / out you need to use an escape code 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. + + pi = 3.1415926 5. Why does this code not work? A = 22 print(a) + This code won't work because capitalization matters and A and a are seen as 2 different variables + 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -31,7 +37,7 @@ Area AREA area - area_of_rectangle + area_of_rectangle - According to standards for python the one to the left is the best way of naming variabels Area_Of_Rectangle 7. Which of these variables names are not allowed in Python? (More than one @@ -42,12 +48,12 @@ Apple APPLE Apple2 - 1Apple - account number + 1Apple - not allowed + account number - not allowed account_number - account.number + account.number - not allowed accountNumber - account# + account# - not allowed pi PI fred @@ -55,21 +61,26 @@ GreatBigVariable greatBigVariable great_big_variable - great.big.variable - 2x + great.big.variable - not allowed + 2x - not allowed x2x - total% - #left + total% - not allowed + #left - not allowed 8. Why does this code not work? print(a) a = 45 + You are assigning a variable a value after you print it so the a being 45 is unknown + by the computer untill after it tried to print a causeing an error + 9. Explain the mistake in this code: pi = float(3.14) + 3.14 is already a float to the computer since it has decimals points which integers can't have so declaring it as a float is redundent + 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -79,6 +90,8 @@ area = pi * radius ** 2 print(area) + There is no reason to have an x variable that only passes a value onto another variable, so pi = 3.14 is better and saves time/space/annoyance + 11. Explain the mistake in the following code: x = 4 @@ -86,6 +99,8 @@ a = ((x) * (y)) print(a) + The parentheses in the a = statment are useless because order of opperations is unimportant for a single operation + 12. Explain the mistake in the following code: x = 4 @@ -93,36 +108,57 @@ a = 3(x + y) print(a) + As humans we can understand that means to distribute but a computer needs to be explicitly told that by doing 3 * (x + y) + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) + Your supposed to put the float in front of the input statment so the input statment can return the correct variable type + 14. Do all these print the same value? Which one is better to use and why? print(2/3+4) print(2 / 3 + 4) print( 2 / 3+ 4 ) + All of them will be understood by the computer, however normal python standards make the second print statment the correct one + 15. What is a constant? + + A variable that remains unchanged throughtout the program such as PI = 3.1415926 16. How are variable names for constants different than other variable names? + + Constant variable names are capililized such as TEST_CONSTANT 17. What is a single quote and what is a double quote? Give and label an example of both. + + ' - This is a single quote + " - This is a double quote 18. Write a Python program that will use escape codes to print a double-quote and a new line using the Window's standard. (Note: I'm asking for the Window's standard here. Look it up out of Chapter 1.) + + print("\"\r\n") 19. Can a Python program print text to the screen using single quotes instead of double quotes? + + Yes it can, print('Hello World') works just as print("Hello World") does 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) + Because of the order of operations the 5 / 3 would happen first and then the others would be added + print((3 + 4 + 5) / 3) would be the correct way of doign it 21. What is an ``operator'' in Python? + + It is a character that stands for a math function such as addition subtraction division ect... 22. What does the following program print out? @@ -130,15 +166,18 @@ x + 1 print(x) - + This program prints out + + 3 + 23. Correct the following code: - user_name = input("Enter your name: )" + user_name = input("Enter your name: ") 24. Correct the following code: - value = int(input(print("Enter your age"))) + value = int(input("Enter your age")) From 54b4b2470259544208640fd7d03fece720c5698c Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Wed, 1 Nov 2017 09:25:34 -0500 Subject: [PATCH 02/14] Finished Lab01 programs a,b,c --- Lab 01 - Calculator/lab_01_part_a.py | 13 ++++++++++++- Lab 01 - Calculator/lab_01_part_b.py | 17 ++++++++++++++++- Lab 01 - Calculator/lab_01_part_c.py | 18 +++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..017ab9b 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,12 @@ -# +#!/usr/bin/env python3 +# lab_01_part_a.py +# Jared Rhodes +# 11/01/2017 + +""" This is the first part of Chapter 1 Lab Pygame """ + +temp_Fahrenheit = float(input("Enter temperature in Fahrenheit: ")) + +temp_Celsius = (temp_Fahrenheit - 32) * .5556 + +print("The temperature in Celsius:", temp_Celsius) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..c603861 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,16 @@ -# +#!/usr/bin/env python3 +# lab_01_part_b.py +# Jared Rhodes +# 11/01/2017 + +""" This is the second part of Chapter 1 Lab Pygame """ + +print("Finding the Area of a Trapezoid") + +height = int(input("Enter the height of the trapezoid: ")) +base_One = int(input("Enter the length of the bottom base: ")) +base_Two = int(input("Enter the length of the top base: ")) + +area = ((base_One + base_Two) * height) / 2 + +print('The area is:', area) \ No newline at end of file diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..8c8f075 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,17 @@ -# +#!/usr/bin/env python3 +# lab_01_part_c.py +# Jared Rhodes +# 11/01/2017 + +""" This is the third part of Chapter 1 Lab Pygame """ + +print("Finding your current damage output") + +attack_Speed = float(input("Please enter your current attack speed: ")) +attack_Damage = float(input("Please enter your current attack damage: ")) +critical_Chance = float(input("Please enter your current critical chance: ")) + +damage_Output = (attack_Speed * attack_Damage) * (1 + (critical_Chance * 1)) + +print('Your current damage per second is:', damage_Output) + From 66fa321418b218eb79784c20d0eea87b05c4f1ba Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Thu, 2 Nov 2017 08:22:21 -0500 Subject: [PATCH 03/14] Finished chapter 2 worksheet --- Worksheets/worksheet_02.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..267a858 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,72 @@ 1. Give an example of a binary number. (While a number such as ``1'' can be a binary, decimal, and hexadecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.) + + 00100100 - 36 it is base 2 for the places 128,64,32,16,8,4,2,1 2. Give an example of a decimal number. + + 13 is a decimal number, decimal numbers use base 10s for the places 3. Give an example of a hexadecimal number. + + Hexadecimal - 24 is equivalent to Decimal - 36, Hexadecimal - 1C is equivalent to Decimal - 28 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. + + In order from left to right they are the values - 1,2,4,8,16 5. What is a compiler? + + A complier is a program that takes the source code and turns it into machine code that is then run by the computer 6. What is source code? + + Source code in the program written by the programmer 7. What is machine language? (Don't just say binary. That's not correct.) + + Machine language is a set of binary numbers that represent commands for the computer to run 8. What is a first generation language? (Don't just say binary. That's not correct.) + + The 1GL is the native language for a computer, which is binary commands 9. What is a second generation language? + + A second generation language also called the assembly language is a set of mnemonics that a complier can convert to machine language 10. What is a third generation language? (Explain, don't just give one example.) + + Third generation languages allowed the programmer to write and understand code easier, and didn't require as much direct input of the programmer. Basically they were more intuitive. 11. What is an interpreter and how does it differ from a compiler? + + An interpreter translates source code into machine code as it gets fed the code, this means as long as an interpreter is made for a language any language can be converted to machine language, using an interpreter + is however slower than using a computers native language 12. Search the web and find some of the most popular programming languages. List the website(s) you got the information from and what the languages are. + + https://www.inc.com/larry-kim/10-most-popular-programming-languages-today.html + + Java, Python, C, JavaScript, and C# are some of the most popular coding languages 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. + + https://www.indeed.com/q-Computer-Programmer-jobs.html + + C, C++, SQL, Visual Basic, VBScript, Java, C# were some of the langauges being looked for 14. What is the difference between the ``syntax'' and ``semantics'' of a language? + + Syntax has to do with how the code is structured, and semantics is the meaning behind the code 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. + I have a hand held tetris game, in it is most likely a small hardrive to store basic score and setting information along with a proccesor of some kind that handles the funtions that happen while + playing tetris. This hardware also needs code that stores how the game is played, this code is most likely also stored on the small hardrive. From b82faf617df80909b8cefcc058396d0acb5baae7 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Fri, 3 Nov 2017 08:06:58 -0500 Subject: [PATCH 04/14] Finished chapter 3 worksheet --- Worksheets/worksheet_03.txt | 74 ++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..8629409 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -5,39 +5,62 @@ 1. What is missing from this code? (1 pt) - temperature = float(input("Temperature: ") + temperature = float(input("Temperature: ")) if temperature > 90: print("It is hot outside.") else: print("It is not hot out.") + + This code was missing a parethese at the end of the input statment 2. Write a Python program that will take in a number from the user and print if it is positive, negative, or zero. Use a proper if/elif/else chain, don't just use three if statements. - + + user_Number = int(input("Please give me a number: ")) + if user_Number > 0: + print("Your number is positive") + elif user_Number < 0: + print("Your number is negative") + else: + print("Your number is zero") + 3. Write a Python program that will take in a number from a user and print out ``Success'' if it is greater than -10 and less than 10, inclusive. (1 pt) + + user_Number = int(input("Please give me a number: ")) + if user_Number >= -10 and user_Number <= 10: + print("Success") + 4. This runs, but there is something wrong. What is it? (1 pt) - user_input = input("A cherry is a: ") + print("A. Dessert topping") print("B. Desert topping") + user_input = input("A cherry is a: ") if user_input.upper() == "A": print("Correct!") else: print("Incorrect.") + + The input statment needs to be put after the print statments because the computer program will wait until input is given before continuing on to print the options + and since the options are needed to answer the question it is important that they get printed before the question is asked 5. There are two things wrong with this code that tests if x is set to a positive value. One prevents it from running, and the other is subtle. Make sure the if statement works no matter what x is set to. Identify both issues. (2 pts) - x == 4 - if x >= 0: + x = 4 + if x > 0: print("x is positive.") else: print("x is not positive.") + + x needs to be assigned using a single equals sign, a double equals sign with check to see if it is equal + + zero is not a positive number so it should just be numbers above zero which return as positive 6. What three things are wrong with the following code? (3 pts) @@ -56,8 +79,10 @@ 8. This program doesn't work correctly. What is wrong? (1 pt) x = input("How are you today?") - if x == "Happy" or "Glad": + if x == "Happy" or x == "Glad": print("That is good to hear!") + + You need to add x == to the Glad also because the computer doesn't know to carry it over from the first one 9. Look at the code below. Write you best guess here on what it will print. Next, run the code and see if you are correct. @@ -78,6 +103,12 @@ print("Fizz") if z: print("Buzz") + + Guess: Actual Result: + x= 5 x= 5 + y= False y= False + z= True z= True + Buzz Buzz 10. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts) @@ -97,6 +128,19 @@ print(x == 5 and y == 5) print(x == 5 or y == 5) + Guess: Actual Result: + True True + False False + True True + False False + False False + True True + True False + True False + True True + False False + True True + 11. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts) @@ -110,6 +154,16 @@ print( (2 == 2) == True ) print(3 < "3") + Guess: Actual Result: + True True + False False + True True + True True + True True + True False + False False + True True + False Unsupported type error 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -123,13 +177,13 @@ user_input = input("What is your occupation?") - if user_input = A: + if user_input == "A": money = 100 - else if user_input = B: + elif user_input == "B": money = 70 - else if user_input = C: + elif user_input == "C": money = 50 - + First the syntax isn't else if it's elif, also A, B, C are strings and thus need to be in quotes, finally user input is being compared not assigned so it shouuld have double equals signs From d3643f8507d4ce50f758ab08ea951284de21f34e Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Fri, 3 Nov 2017 09:49:42 -0500 Subject: [PATCH 05/14] Finished Chapter 3 lab --- Lab 03 - Create a Quiz/main_program.py | 87 +++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..120eac0 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,86 @@ -# +#!/usr/bin/env python3 +# main_program.py +# Jared Rhodes +# 11/03/2017 + +""" This is the quiz game for chapter 3's lab """ + +num_Correct = 0 + + + +print("This is a quiz game to test your knowlege of random facts") +print("This quiz with consist of 6 questions on varying subjects") + +print("Question Number 1") +print("What is the atomic number for Lithium?") +print("A. 6\nB. 8\nC. 5\nD. 3") +usr_Ans = input() + +if usr_Ans.upper() == "D": + print("Your answer was correct") + num_Correct += 1 +else: + print("Your answer was incorrect") + + +print("Question Number 2") +print("What is the biggest animal?") +print("A. Elephant\nB. Blue Whale\nC. Sperm Whale\nD. Great White Shark") +usr_Ans = input() + +if usr_Ans.upper() == "B": + print("Your answer was correct") + num_Correct += 1 +else: + print("Your answer was incorrect") + +print("Question Number 3") +print("How many planets are there in our solar system?") +print("A. Eight\nB. Nine\nC. Seven\nD. Ten") +usr_Ans = input() + +if usr_Ans.upper() == "A": + print("Your answer was correct") + num_Correct += 1 +else: + print("Your answer was incorrect") + +print("Question Number 4") +print("What fictional universe do the Borg come from?") +print("A. Star Trek\nB. Firefly\nC. Star Wars\nD. Dark Matter") +usr_Ans = input() + +if usr_Ans.upper() == "A": + print("Your answer was correct") + num_Correct += 1 +else: + print("Your answer was incorrect") + +print("Question Number 5") +print("What percent of the earth's surface is water?") +print("A. 70%\nB. 72%\nC. 64%\nD. 71%") +usr_Ans = input() + +if usr_Ans.upper() == "D": + print("Your answer was correct") + num_Correct += 1 +else: + print("Your answer was incorrect") + +print("Question Number 6") +print("Which country borders China?") +print("A. Thailand\nB. South Korea\nC. India\nD. Japan") +usr_Ans = input() + +if usr_Ans.upper() == "C": + print("Your answer was correct") + num_Correct += 1 +else: + print("Your answer was incorrect") + +print("Congradulations on completing my Quiz") +print("You scored a", num_Correct, "out of 6") +print("This is a", str(num_Correct / 6) + "%") + + From 8b23ebf22962805cf578daf9882146c8c8335fe7 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Mon, 6 Nov 2017 09:04:04 -0600 Subject: [PATCH 06/14] Finsihed Chapter 3/4 worksheets --- Worksheets/worksheet_03.txt | 2 +- Worksheets/worksheet_04.txt | 104 ++++++++++++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index 8629409..2aafd1b 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -184,6 +184,6 @@ elif user_input == "C": money = 50 - First the syntax isn't else if it's elif, also A, B, C are strings and thus need to be in quotes, finally user input is being compared not assigned so it shouuld have double equals signs + First the syntax isn't else if it's elif, also A, B, C are strings and thus need to be in quotes, finally user_input is being compared not assigned so it shouuld have double equals signs diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..5429dfd 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,17 +13,33 @@ 1. Write a Python program that will use a for loop to print your name 10 times, and then the word ``Done'' at the end. + + for i range(10): + print("Jared Rhodes") + print("Done") 2. Write a Python program that will use a for loop to print ``Red'' and then ``Gold'' 20 times. (Red Gold Red Gold Red Gold... all on separate lines. Don't use \n.) + + for i range(20): + print("Red") + print("Gold") 3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive. + + for i in range(2,102,2): + print(i) 4. Write a Python program that will use a while loop to count from 10 down to, and including, 0. Then print the words ``Blast off!'' Remember, use a WHILE loop, don't use a FOR loop. + + counter = 10 + while counter > 0: + print(counter) + counter -= 1 5. There are three things wrong with this program. List each. (3 pts) @@ -31,15 +47,24 @@ total = 0 for i in range(3): - x = input("Enter a number: ") - total = total + i - print("The total is:", x) + x = int(input("Enter a number: ")) + total = total + x + print("The total is:", total) + + x not i should be added to the total since that is where the numbers are stored, the total is not stored in x it's stored in total so we should print total, finally x needs to be an integer so that you can add it + to total and not be a string 6. Write a program that prints a random integer from 1 to 10 (inclusive). + + import random + print(random.randint(1, 10)) 7. Write a program that prints a random floating point number somewhere between 1 and 10 (inclusive). Do not make the mistake of generating a random number from 0 to 10 instead of 1 to 10. + + import random + print(random.random() * 9 + 1) 8. Write a Python program that will: (3 pts) @@ -49,6 +74,22 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. +num_Positive = 0 +num_Negative = 0 +num_Zero = 0 +summation = 0 + +for i in range(7): + num = int(input("Please give me a number: ")) + summation += num + if num > 0: + num_Positive += 1 + elif num < 0: + num_Negative += 1 + else: + num_Zero += 1 +print("There was", num_Positive, "positive numbers", num_Negative, "negative numbers, and", num_Zero, "zeros") + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +98,22 @@ * Add a loop so that the program does this 50 times. * Create a running total for the number of heads flipped, and the number of tails. +import random + +random_Binary = 0 +num_H = 0 +num_T = 0 + +for i in range(50): + random_Binary = random.randint(0,1) + if random_Binary == 1: + print('Heads') + num_H += 1 + if random_Binary == 0: + print('Tails') + num_T += 1 +print("Heads:", num_H, "\nTails:", num_T) + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -65,5 +122,44 @@ * Add to the program so it first asks the user their choice. * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. - + +import random + +usr_Choice = int(input("Would you like \n1. Rock \n2. Paper \n3. Scissors\n")) + +random_Choice = random.randint(1,3) + +if usr_Choice == 1: + print("Rock") +elif usr_Choice == 2: + print("Paper") +else: + print("Scissors") + +print("vs.") + +if random_Choice == 1: + print("Rock") +elif random_Choice == 2: + print("Paper") +else: + print("Scissors") + +if usr_Choice == random_Choice: + print("You tied") +elif usr_Choice == 1 and random_Choice == 2: + print('You lose') +elif usr_Choice == 1 and random_Choice == 3: + print('You win') +elif usr_Choice == 2 and random_Choice == 1: + print('You win') +elif usr_Choice == 2 and random_Choice == 3: + print('You lose') +elif usr_Choice == 3 and random_Choice == 1: + print('You lose') +elif usr_Choice == 3 and random_Choice == 2: + print('You win') +else: + print("Something went wrong") + From 8e1efbcdc74cc5397a52cf8dd6141a367aa243e0 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Tue, 7 Nov 2017 07:34:21 -0600 Subject: [PATCH 07/14] Finished Chapter 4 lab --- Lab 04 - Camel/main_program.py | 96 +++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..cb5ca0a 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,95 @@ -# +import random + +print("Welcome to Camel!") +print("You have stolen a camel to make your way across the great Mobi desert") +print("The natives want their camel back and are chasing you down!") +print("Survive crossing the desert, and outrun those natives!") + +done = False +miles = 0 +thirst = 0 +tiredness = 0 +native_Miles = -20 +canteen_Drinks = 3 + +while done == False: + print("Your choices are -----------") + print("A. Drink from your canteen") + print("B. Ahead moderate speed") + print("C. Ahead full speed") + print("D. Stop for the night") + print("E. Status check") + print("Q. Quit") + usr_Decision = input() + + if usr_Decision.upper() == "Q": + done = True + + if usr_Decision.upper() == "E": + print("You currently have", canteen_Drinks, + "drinks left in your canteen") + print("You currently have traveled", miles, + "miles") + print("The natives are currently", miles - native_Miles, + "miles behind you") + + if usr_Decision.upper() == "D": + print("Your camel thanks you!") + tiredness = 0 + native_Miles += random.randint(7, 14)\ + + if usr_Decision.upper() == "C": + miles_Traveled = random.randint(10, 20) + print("You traveled", miles_Traveled, "miles") + miles += miles_Traveled + tiredness += random.randint(1, 3) + thirst += 1 + native_Miles += random.randint(7, 14) + + if usr_Decision.upper() == "B": + miles_Traveled = random.randint(5, 12) + print("You traveled", miles_Traveled, "miles") + miles += miles_Traveled + tiredness += 1 + thirst += 1 + native_Miles += random.randint(7, 14) + + if usr_Decision.upper() == "A": + if canteen_Drinks >= 1: + print("You take a drink, and feel refreshed") + canteen_Drinks -= 1 + thirst = 0 + else: + print("You don't have any drinks left :(") + + if thirst > 4: + print("You are thirsty") + elif thirst > 6: + print("You died of thirst") + done = True + + if tiredness > 5: + print("Your camel is getting tired") + elif tiredness > 8: + print("Your camel died") + done = True + + if native_Miles >= miles: + print("You done got caught, by the natives") + done = True + elif native_Miles >= miles - 15: + print("The natives are getting close!") + + if miles >= 200: + print("You made it through the desert!") + print("You win, you didn't die, that is equaivalent to winning!") + done = True + + chance = random.randint(1, 20) + + if chance == 1: + print("You stumbled on an oasis") + canteen_Drinks = 3 + thirst = 0 + tiredness = 0 + \ No newline at end of file From 6b20bf654e1cbe964e1fef5ee5c9f731a4a51b63 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Thu, 9 Nov 2017 09:58:38 -0600 Subject: [PATCH 08/14] finished 4/5 labs and 5 worksheet --- Lab 04 - Camel/main_program.py | 7 +++ Lab 05 - Create a Picture/main_program.py | 55 ++++++++++++++++++++++- Worksheets/worksheet_05.txt | 51 +++++++++++++++++---- 3 files changed, 104 insertions(+), 9 deletions(-) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index cb5ca0a..010df0e 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1,3 +1,10 @@ +#!/usr/bin/env python3 +# main_program.py +# Jared Rhodes +# 11/07/2017 + +""" This is the camel game lab from chapter 4 """ + import random print("Welcome to Camel!") diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..ae11a23 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,54 @@ -# +#!/usr/bin/env python3 +# main_program.py +# Jared Rhodes +# 11/09/2017 + +""" This is the draw pictue lab from chapter 5 """ + +import pygame + +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) +YELLOW = (255, 255, 0) +SKYBLUE = (0, 255, 255) +BROWN = (155, 100, 0) +BLUE = (0, 0, 255) +PI = 3.1415926 + +pygame.init() +size = (700, 500) +max_X = 700 +max_Y = 500 +screen = pygame.display.set_mode(size) + +done = False + + +clock = pygame.time.Clock() +while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + screen.fill(WHITE) + + pygame.draw.rect(screen, SKYBLUE, [0, 0, 700, 400]) + pygame.draw.circle(screen, YELLOW, [100, 100], 100) + pygame.draw.rect(screen, GREEN, [0, 400, 700, 500]) + pygame.draw.rect(screen, BROWN, [400, 350, 30, 80]) + pygame.draw.circle(screen, GREEN, [415, 250], 100) + pygame.draw.lines(screen, BLACK, False, [(600, 100), (610, 110), (620, 100)], 4) + pygame.draw.lines(screen, BLACK, False, [(500, 140), (510, 150), (520, 140)], 3) + pygame.draw.lines(screen, BLACK, False, [(550, 180), (560, 190), (570, 180)], 2) + pygame.draw.circle(screen, RED, [360, 220], 9) + pygame.draw.circle(screen, RED, [430, 240], 9) + pygame.draw.circle(screen, RED, [460, 200], 9) + pygame.draw.circle(screen, RED, [420, 320], 9) + pygame.draw.circle(screen, RED, [350, 295], 9) + pygame.draw.circle(screen, RED, [480, 285], 9) + pygame.draw.arc(screen, BLUE, [100,340,220,120], PI, 4*PI/2, 60) + + pygame.display.flip() + clock.tick(60) +pygame.quit() \ No newline at end of file diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..cb88893 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -7,63 +7,98 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + + 1. The coordinates on a screen start in the top left vs. Cartesian planes start at the middle + 2. The coordinates on a screen focus on the lower right quadrant vs Cartesian focuses on the upper right quadrant 2. Before a Python Pygame program can use any functions like pygame.display.set_mode(), what two lines of code must occur first? + + import pygame + pygame.init() 3. Explain how WHITE = (255, 255, 255) represents a color. + + The three numbers in this case 255, 255, 255 are the red blue and green values that create the color white 4. When do we use variable names for colors in all upper-case, and when do we use variable names for colors in all lower-case? (This applies to all variables, not just colors.) + + The full uppercase variables mean that variable should remain at the same value, a lowercase variable means that variable will most likely be changed + such as a color of a health bar that changed to red as the health went down 5. What does the pygame.display.set_mode() function do? - + + This function gives control over everything about the screen, start menu, titles bars, the size of the screen. It's the main control function for the screen + 6. What does this for event in pygame.event.get() loop do? + + This function grabs all of the different events that happen to the screen, so that they can then cause the program to do something 7. What is pygame.time.Clock used for? + + the pygame.time.Clock is used to set the fps(frames per second) or in other words the number of times the screen updates per second 8. For this line of code: (3 pts) pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5) - * What does screen do? - * What does [0, 0] do? - * What does [100, 100] do? - * What does 5 do? + * What does screen do? screen is where the computer will be drawing the line + * What does [0, 0] do? 0, 0 is the starting point for the line + * What does [100, 100] do? 100, 100 is the ending point for the line + * What does 5 do? 5 is the width of the line 9. What is the best way to repeat something over and over in a drawing? + + Repeating is done using loops, if you want it to be drawn in different places using a variable that changes with each loop can make that happen 10. When drawing a rectangle, what happens if the specified line width is zero? + + The whole rectangle will be filled with the given color 11. Describe the ellipse drawn in the code below. - * What is the x, y of the origin coordinate? - * What does the origin coordinate specify? The center of the circle? - * What is the length and the width of the ellipse? + * What is the x, y of the origin coordinate? - (20, 20) is the starting coordinate + * What does the origin coordinate specify? The center of the circle? - No, the origin is the top left corner that the circle is drawn starting from + * What is the length and the width of the ellipse? - The length is 230 pixels, the width is 80 pixels pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) 12. When drawing an arc, what additional information is needed over drawing an ellipse? + + The arc command requires start and stop angles so it knows how big of an arc to draw 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + + First you need to select the font, and it's size. Then you need to render the the text putting it in a buffer to be displayed. Finally you need to put the image on the screen using screen.blit([]) 14. When drawing text, the first line of the three lines needed to draw text should actually be outside the main program loop. It should only run once at the start of the program. Why is this? You may need to ask. + + Only one font should be used in a program, having multiple fonts will make things hard to read 15. What are the coordinates of the polygon that the code below draws? pygame.draw.polygon(screen, BLACK, [[50,100],[0,200],[200,200],[100,50]], 5) + This draws a rectangle with corners at 50,100 0,200 200,200 100,50 with a line width of 5 + 16. What does pygame.display.flip() do? + + Flip tells the screen to update and display the lines/rect ect. that are in the buffer 17. What does pygame.quit() do? + + pygame.quit() end the program and closes the screen 18. Look up on-line how the pygame.draw.circle works. Get it working and paste a working sample here. I only need the one line of code that draws the circle, but make sure it is working by trying it out in a full working program. + pygame.draw.circle(screen, BLACK, [100, 100], 100, 10) + From ff454d2d0f957dc43cc772b05f1f4cef99375a66 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Thu, 9 Nov 2017 10:04:08 -0600 Subject: [PATCH 09/14] fixed lab 5 --- Lab 05 - Create a Picture/main_program.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index ae11a23..c49c56b 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -32,10 +32,11 @@ if event.type == pygame.QUIT: done = True screen.fill(WHITE) - + + pygame.draw.rect(screen, GREEN, [0, 400, 700, 500]) + pygame.draw.ellipse(screen, BLUE, [100,340,220,120]) pygame.draw.rect(screen, SKYBLUE, [0, 0, 700, 400]) pygame.draw.circle(screen, YELLOW, [100, 100], 100) - pygame.draw.rect(screen, GREEN, [0, 400, 700, 500]) pygame.draw.rect(screen, BROWN, [400, 350, 30, 80]) pygame.draw.circle(screen, GREEN, [415, 250], 100) pygame.draw.lines(screen, BLACK, False, [(600, 100), (610, 110), (620, 100)], 4) @@ -47,7 +48,7 @@ pygame.draw.circle(screen, RED, [420, 320], 9) pygame.draw.circle(screen, RED, [350, 295], 9) pygame.draw.circle(screen, RED, [480, 285], 9) - pygame.draw.arc(screen, BLUE, [100,340,220,120], PI, 4*PI/2, 60) + pygame.display.flip() clock.tick(60) From ad5159cda8f72e5c78751bc2fab86755e66beb4a Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Tue, 14 Nov 2017 10:12:22 -0600 Subject: [PATCH 10/14] Finished up to problem 5 chapter 6 worksheet --- Worksheets/worksheet_06.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..549c7d9 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,10 @@ while x < 10: print(x) x = x + 2 + + Guess: print 0, 2, 4, 6, 8 on seperate lines + + Answer: Prints out 0, 2, 4, 6, 8 on seperate lines 2. What does this program print out? @@ -24,6 +28,10 @@ while x < 64: print(x) x = x * 2 + + Guess: print 1,2,4,8,16,32 on seperate lines + + Answer: Prints out 0, 1,2,4,8,16,32 on seperate lines 3. Why is the and x >= 0 not needed? @@ -31,6 +39,8 @@ while x < 10 and x >= 0: print(x) x = x + 2 + + x is never pushed down during the loop, so x >= 0 will always return true, making it useless 4. What does this program print out? (0 pts) Explain. (1 pt) @@ -40,6 +50,8 @@ if x == "1": print("Blast off!") x = x - 1 + + It doesn't print blast off, just 5,4,3,2,1,0. This is because x is an integer however "1" is a string and int/str are never equal 5. Fix the following code so it doesn't repeat forever, and keeps asking the user until he or she enters a number greater than zero: (2 pts) @@ -47,7 +59,9 @@ x = float(input("Enter a number greater than zero: ")) while x <= 0: - print("Too small. Enter a number greater than zero: ") + print("Too small. Enter a number greater than zero: ") + x = float(input("Enter a number greater than zero: ")) + 6. Fix the following code: From efe569ca7adb46700769fce2ed821e9f8eef9e94 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Wed, 15 Nov 2017 08:03:19 -0600 Subject: [PATCH 11/14] Finished 6-8 chapter 6 worksheet --- Worksheets/worksheet_06.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 549c7d9..63a3a1e 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -67,12 +67,14 @@ x = 10 - while x < 0: + while x > 0: print(x) - x - 1 + x = x - 1 print("Blast-off") + + 7. What is wrong with this code? It runs but it has unnecessary code. Find all the unneeded code. Also, answer why it is not needed. (1 pt) @@ -81,6 +83,8 @@ print(i) i += 1 + The i = 0 and the i += 1 should be removed, they are the syntax for a while loop and are unesscary when making a for loop + 8. Explain why the values printed for x are so different. (2 pts) # Sample 1 @@ -99,4 +103,6 @@ x += 1 print(x) + When you nest loops like in the second example, it acts like a multiply funtion running the entire second loop for every loop of the outside, creating a much bigger number + than just adding the values of the two loops together like in the first example. From e305b30dcd6197738acb8b9cae9cde965cf5f25f Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Wed, 15 Nov 2017 08:12:58 -0600 Subject: [PATCH 12/14] Finished Chp.6 part 1 Lab --- Lab 06 - Loopy Lab/part_1.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..37a924a 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,14 @@ +#!/usr/bin/env python3 +#part_1.py +#Jared Rhodes +#November 5, 2017 +""" Part 1 of Chapter 6 Loopy Lab """ + +diget = 10 + +for row in range(1,10): + for col in range(row): + print(diget,end=" ") + diget += 1 + print() \ No newline at end of file From 042c7d92fb453224fe103274cea2456888c51453 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Wed, 15 Nov 2017 09:25:35 -0600 Subject: [PATCH 13/14] Finished part 3 Chp.6 Lab --- Lab 06 - Loopy Lab/part_2.py | 41 +++++++++++++++++++++++++++++++++++- Lab 06 - Loopy Lab/part_3.py | 32 +++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..946d9ee 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,40 @@ -# +#!/usr/bin/env python3 +#part_2.py +#Jared Rhodes +#November 5, 2017 + +""" Part 2 of Chapter 6 Loopy Lab """ + +size = int(input("What size box would you like? ")) + + +for width_Top in range(size * 2): + print("o",end="") +print() + +for height in range(size - 2): + print("o" + (" " * (size * 2 - 2)) + "o") + +for width_Bottom in range(size * 2): + print("o",end="") +print() + +#This is how to make real boxes! + +""" + +size = int(input("What size box would you like? ")) + + +for width_Top in range(size * 2): + print("▀",end="") +print() + +for height in range(size - 2): + print("█" + (" " * (size * 2 - 2)) + "█") + +for width_Bottom in range(size * 2): + print("▄",end="") +print() + +""" \ No newline at end of file diff --git a/Lab 06 - Loopy Lab/part_3.py b/Lab 06 - Loopy Lab/part_3.py index 792d600..213eae2 100644 --- a/Lab 06 - Loopy Lab/part_3.py +++ b/Lab 06 - Loopy Lab/part_3.py @@ -1 +1,31 @@ -# +#!/usr/bin/env python3 +#part_3.py +#Jared Rhodes +#November 5, 2017 + +""" Part 3 of Chapter 6 Loopy Lab """ + +size = int(input("What size shape would you like? ")) + +top_Number = 0 +diget = 1 +line_List = [] + +top_Number = size * 2 + +for row in range(size): + print() + for col in range(1 + (2 * row), top_Number + 1, 2): + print(col,end=" ") + print(" " * row,end="") + for col2 in range(top_Number - 1, 0 + (2 * row), -2): + print(col2,end=" ") + + +for row2 in range(size, -1, -1): + for col in range(1 + (2 * row2), top_Number + 1, 2): + print(col,end=" ") + print(" " * row2,end="") + for col2 in range(top_Number - 1, 0 + (2 * row2), -2): + print(col2,end=" ") + print() \ No newline at end of file From 083f7e439b04ef6fa4ceb287488012e59c75dc91 Mon Sep 17 00:00:00 2001 From: Jrhod99 Date: Wed, 15 Nov 2017 09:57:29 -0600 Subject: [PATCH 14/14] Finished part 4 Chp.6 Lab --- Lab 06 - Loopy Lab/part_4.py | 81 +++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..36dbb42 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,80 @@ -# +#!/usr/bin/env python3 +#part_4.py +#Jared Rhodes +#November 5, 2017 + +""" Part 4 of Chapter 6 Loopy Lab """ + +""" + Pygame base template for opening a window + + Sample Python/Pygame Programs + Simpson College Computer Science + http://programarcadegames.com/ + http://simpson.edu/computer-science/ + + Explanation video: http://youtu.be/vRB_983kUMc +""" + +# I'm not cheating they told us to copy the base code. + +import pygame + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) +SKYBLUE = (0, 255, 255) + +pygame.init() + +# Set the width and height of the screen [width, height] +size = (700, 500) +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("My Game") + +# Loop until the user clicks the close button. +done = False + +# Used to manage how fast the screen updates +clock = pygame.time.Clock() + +# -------- Main Program Loop ----------- +while not done: + # --- Main event loop + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + # --- Game logic should go here + + # --- Screen-clearing code goes here + + # Here, we clear the screen to white. Don't put other drawing commands + # above this, or they will be erased with this command. + + # If you want a background image, replace this clear with blit'ing the + # background image. + screen.fill(BLACK) + + # --- Drawing code should go here + Alternater = 1 + for x in range(0, 700, 10): + for y in range(0, 500, 10): + Alternater *= -1 + if Alternater == 1: + rect_Color = GREEN + else: + rect_Color = SKYBLUE + pygame.draw.rect(screen, rect_Color, [x, y, 6, 6]) + Alternater *= -1 + # --- Go ahead and update the screen with what we've drawn. + pygame.display.flip() + + # --- Limit to 60 frames per second + clock.tick(60) + +# Close the window and quit. +pygame.quit() \ No newline at end of file