From 3f10b353a3ecfcf32824525530a35b5a4add5cf7 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 2 Nov 2017 08:46:29 -0500 Subject: [PATCH 01/26] Completed Chapter 1 --- Lab 01 - Calculator/lab_01_part_a.py | 5 ++- Lab 01 - Calculator/lab_01_part_b.py | 6 ++- Lab 01 - Calculator/lab_01_part_c.py | 5 ++- Worksheets/worksheet_01.txt | 64 +++++++++++++++++----------- 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..01e59a6 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,4 @@ -# +#1.1 part A +Fahrenheit = int(input("Enter temperature in Fahrenheit: ")) +Celsius = (Fahrenheit - 32)*5/9 +print("The temperature in Celsius:",Celsius) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..f015e94 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,5 @@ -# +# 1.2 Part B +height = int(input("Enter the height of the trapezoid: ")) +base = int(input("Enter the length of the bottom base: ")) +top = int(input("Enter the length of the top base: ")) +print("The area is: ", ((top + base) * height) / 2) diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..d4a1e6f 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,4 @@ -# +#1.3 Part C +problem = int(input("Enter the radius: ")) +circle = 3.14 * problem**2 +print(circle) diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..177cfa4 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 01 Worksheet @@ -6,23 +6,24 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. - +name = input('What is your name? ') +print(name) 2. How do you enter a comment in a program? - +# This is a comment! 3. What do the following lines of code output? ALSO: Why do they give a different answer? - + 2 / 3 and 2 // 3 print(2 / 3) print(2 // 3) - + They give put two different answers because 2 / 3 is dividing and 2 // 3 is only giving the rounded down amount. 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. - +pi = 3.14 5. Why does this code not work? A = 22 print(a) - +This code does not work because the 'A' variable is different from the variable used in the print statement. It should be, print(A). 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -33,7 +34,7 @@ area area_of_rectangle Area_Of_Rectangle - +The best variable to use would be area_of_rectangle, because it is descriptive of what the variable is describing. 7. Which of these variables names are not allowed in Python? (More than one might be wrong. Also, this question is not asking about improper names, just names that aren't allowed. Test them if you aren't sure.) @@ -60,16 +61,20 @@ x2x total% #left - + 1Apple + account number + acount.number + account# +The variables are 1Apple, account number, account.number, account#. great.big.variable, account_number. 8. Why does this code not work? print(a) a = 45 - +The variable needs to be before the print statement. 9. Explain the mistake in this code: pi = float(3.14) - +It outputs the code 3.14 if it was being printed, but it was placed into a string not a print statement so the computer doesn't read it as a string. 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -78,14 +83,20 @@ pi = x area = pi * radius ** 2 print(area) - +multiple statements found while compiling a single statement. +radius = input("Radius:") + radius = float(radius) + x = 3.14 + pi = x + area = pi * radius ** 2 + 11. Explain the mistake in the following code: x = 4 y = 5 a = ((x) * (y)) print(a) - +multiple statements found while compiling a single statement. 12. Explain the mistake in the following code: x = 4 @@ -96,50 +107,53 @@ 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) - +Syntax error multiple statements. 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 ) - +Yes all of them are the same print value. The first one because it is the most simple. 15. What is a constant? - +A constant is when you set something too one thing like a value of a variable. 16. How are variable names for constants different than other variable names? - +The variable name can be changed in the code later on but the cosntants have a given value and thus can't be changed. 17. What is a single quote and what is a double quote? Give and label an example of both. - +'Hi.' single quote. "Hello." 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("I want to print a double quote \" for some reason.") 19. Can a Python program print text to the screen using single quotes instead of double quotes? - +Yes a python program can print text to the screen using single quotes instead of double quotes. 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) - +This code doesn't calculate the average because the code doesn't read the order of operations. 21. What is an ``operator'' in Python? - +It stores a value into variable to used later on in the code. 22. What does the following program print out? x = 3 x + 1 print(x) - +It prints out 3. 23. Correct the following code: user_name = input("Enter your name: )" - +It should look like this, +user_name("Enter your name: ") +print(user_name) 24. Correct the following code: value = int(input(print("Enter your age"))) - +value = int(input("Enter your age: ")) +print(value) From d77ff94ce7631863f991c2661c94717a6c354637 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Mon, 6 Nov 2017 08:05:50 -0600 Subject: [PATCH 02/26] Completed Chapter 3 --- Lab 03 - Create a Quiz/main_program.py | 37 +++++++++++- Worksheets/worksheet_02.txt | 32 +++++------ Worksheets/worksheet_03.txt | 80 +++++++++++++++++++++----- 3 files changed, 118 insertions(+), 31 deletions(-) diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..0a2b7ed 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,36 @@ -# +#This will be a quiz. +question_1 = input("1. What is Master Chief's name? ") +correct = 0 +incorrect = 0 +if question_1 == "John": + correct += 1 + print("Correct.") +else: + print("Incorrect.") +question_2 = int(input("2. What is Master Chief's service tag number? ")) +if question_2 == 117: + correct += 1 + print("Correct.") +else: + print("Incorrect.") +question_3 = input("3. What is Master Chief's partner's name? ") +if question_3 == "Cortana": + correct = correct + 1 + print("Correct.") +else: + print("Incorrect.") +question_4 = input("4. Who is the Master Chief uneasy allies with? ") +if question_4 == "Arbiter": + correct += 1 + print("Correct.") +else: + print("Incorrect.") +question_5 = input("5. What is the name of Master Chief's armor? ") +if question_5 == "MJOLNIR": + correct += 1 + print("Correct.") +else: + print("Incorrect.") + +print("You got", correct, "right.") +print("Your score was", (correct/5)*100) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..072434f 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 02 Worksheet @@ -6,37 +6,37 @@ 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.) - +binary: 01110101 (117) 2. Give an example of a decimal number. - +decimal: 117 3. Give an example of a hexadecimal number. - +hexadecimal: 75 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. - +1 = 1, 10 = 2, 100 = 4, 1000 = 8, 10000 = 16 5. What is a compiler? - +A compiler takes a program written by the user, or soucre code, and turns it into a machine code. 6. What is source code? - +The soucre code is a text that lists commands to be compiled into an workable computer programming. 7. What is machine language? (Don't just say binary. That's not correct.) - +Machine code is compuiter programming language consisting of binary or hexadecimal intructions that computers can respond to directly. 8. What is a first generation language? (Don't just say binary. That's not correct.) - +The 1GL consists of only ones and zeros to represent numbers in binary number system. 9. What is a second generation language? - +The 2GL is called assembly language because each command used a mnemonic program called compiler to change the mnemonics into numbers that represent the commands. 10. What is a third generation language? (Explain, don't just give one example.) - +The 3GL is called a compiler that takes program typed in by the user and then turns it into machine code. 11. What is an interpreter and how does it differ from a compiler? - +An interpreter looks at the source code and interprets it to machine language instructions on the fly, while compiler only takes the source code without looking at it. 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://blog.newrelic.com/2017/10/09/popular-programming-languages-2017/ Java is the programming language skill most demand among empolyers. JavaScript .NET HTML Python SQL C or C++ Node.js Ruby PHP. 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. - +Java, JavaScript, Python, PHP, C#, C++, CSS, Ruby, C, Objective-C. 14. What is the difference between the ``syntax'' and ``semantics'' of a language? - +Syntax is a rule of governng the construction of valid statements in a language. Semantics refers to the set of rules of programming language are violated or misused. 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - +My phone. It uses apps to entertain me and occupy my time. My phone also has regular updates, user interface framework, and application suite. diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..288a57b 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 03 Worksheet @@ -10,14 +10,27 @@ print("It is hot outside.") else: print("It is not hot out.") - + It should be written like this +temperature = int(input("Temperature: ")) +if temperature > 90: + print("It is hot outside.") +else: + print("It is not hot out.") 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. - +number = int(input("Enter a number: ")) +if number > 0: + print(number, "is positive.") +elif number < 0: + print(number, "is negative.") +else: + print(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) - +number = int(input("Enter a number: ")) +if number <= 10 and number >= -10: + print('Success') 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -27,7 +40,13 @@ print("Correct!") else: print("Incorrect.") - +It should look like this, + +user_input = input("A cherry is a: ") +if user_input.upper() == "A": + print("Correct!") +else: + print("Incorrect.") 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. @@ -38,13 +57,19 @@ print("x is positive.") else: print("x is not positive.") - +The code should be written like this, +number = int(input("Enter a number: ")) +number == 4 +if number >= 0: + print(number, "is positive.") +else: + print(number, "is not positive.") 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") - +There is an invalid syntax. There is no ':'. There isn't an int on the first line of coding to acknowledge that it is a number. 7. There are four things wrong with this code. Identify all four issues. (4 pts) answer = input("What is the name of Dr. Bunsen Honeydew's assistant? ") @@ -52,13 +77,15 @@ print("Correct!") else print("Incorrect! It is Beaker.") - +There is an unexpected indent at the if statement, as well as at the else statement. +The else staement has no ':'. +The variables aren't the same. 8. This program doesn't work correctly. What is wrong? (1 pt) x = input("How are you today?") if x == "Happy" or "Glad": print("That is good to hear!") - +Regardless of what you type the program responds with, "That is good to hear!". 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. Clearly label your guess and the actual answer. @@ -78,8 +105,12 @@ print("Fizz") if z: print("Buzz") - - 10. Look at the code below. Write you best guess on what it will print. +Guess: I believe the code will print out that it is unable to load what the user wants it to respond to. + + +Answer: The actual answer was x= 5 y= False z= True 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) x = 5 @@ -96,7 +127,18 @@ print(x == 5 and y == 10) print(x == 5 and y == 5) print(x == 5 or y == 5) - +Guess: print x is equal to 5. print y is equal to 10. print y is less than z. print x is less than y. +Answer: True + False + True + False + False + True + False + False + True + False + 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) @@ -109,7 +151,17 @@ print( (2 == 2) == "True" ) print( (2 == 2) == True ) print(3 < "3") - +Guess: print 3 == 3 is true "3" == " 3" false true true 3 and 4 3 and 10 true true false + +Answer: There was an error at the very end of the code. +True +False +True +True +True +False +False +True 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -129,7 +181,7 @@ money = 70 else if user_input = C: money = 50 - +Things wrong with the program are the variables need a == before it as well as being in "". Also change else if to elif and the second else if to just else:. From 162fa38fe5cd05debf646c74e1daab9142961ea5 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 9 Nov 2017 09:37:59 -0600 Subject: [PATCH 03/26] Completed Chapter 4 --- Lab 04 - Camel/main_program.py | 99 ++++++++++++++++++++++++++++++- Worksheets/worksheet_04.txt | 103 ++++++++++++++++++++++++++++++--- 2 files changed, 193 insertions(+), 9 deletions(-) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..e0926a9 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,98 @@ -# +import random + +print("Welcome to Camel!") +print("""You have stolen a camel to make your way across the great Mobi desert. +The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.""") +print() + +#variables +oasis = 100 +milesTraveled = 0 +thirst = 0 +camelFatigue = 0 +nativesTraveled = -20 +canteen = 3 +done = False + + +#start main loop +while not done: + nativesBehind = milesTraveled - nativesTraveled + fullSpeed = random.randrange(10, 21) + moderateSpeed = random.randrange(5, 13) + print(""" + A. Drink from your canteen. + B. Ahead at moderate speed. + C. Ahead full speed. + D. Stop for the night. + E. Status check + Q. Quit.""") + print() + userInput = input("Your choice? ") + if userInput.lower() == "q": + done = True + +#status + elif userInput.lower() == "e": + print("Miles traveled: ",milesTraveled) + print("Drinks in canteen: ",canteen) + print("Your camel has ",camelFatigue,"amount of fatigue.") + print("The natives are ",nativesBehind,"miles behind you.") +#stop for night + elif userInput.lower() == "d": + camelFatigue *= 0 + print("Your camel feels refreshed and happy his fatigue is now ",camelFatigue) + nativesTraveled += random.randrange(7, 15) +#move full speed + elif userInput.lower() == "c": + print("You traveled ",fullSpeed,"miles!") + milesTraveled += fullSpeed + thirst += 1 + camelFatigue += random.randrange(1, 4) + nativesTraveled += random.randrange(7, 15) + oasis = random.randrange(1, 21) + +#move moderate speed + elif userInput.lower() == "b": + print("You traveled ",moderateSpeed,"miles!") + milesTraveled += moderateSpeed + thirst += 1 + camelFatigue += 1 + nativesTraveled += random.randrange(7, 15) + oasis = random.randrange(1, 21) + + #drink canteen + elif userInput.lower() == "a": + if canteen == 0: + print("You're out of water.") + else: + canteen -= 1 + thirst *= 0 + print("You have ",canteen,"drinks left and you are no longer thirsty.") + +#not done check + if oasis == 20: + camelFatigue *= 0 + thirst *= 0 + canteen = 3 + print("You found an oasis! After taking a drink you filled your canteen and the camel is refreshed.") + if nativesBehind <= 15: + print("The natives are drawing near!") + if milesTraveled >= 200 and not done: + print("You made it across the desert, you win!") + done = True + if nativesTraveled >= milesTraveled: + print("The natives caught and beheaded you.") + print("You're dead!") + done = True + if thirst > 4 and thirst <= 6 and not done: + print("You are thirsty") + if thirst > 6: + print("You died of dehydration!") + done = True + if camelFatigue > 5 and camelFatigue <= 8 and not done: + print("Your camel is getting tired.") + if camelFatigue > 8: + print("Your camel is dead.") + done = True + diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..875fde9 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 04 Worksheet @@ -13,17 +13,31 @@ 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. +name = input("Enter your name: ") + +for i in range(10): + print(name) +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 in 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. +i = 10 +while i > -1: + print(i) + i = i - 1 +print("Blast off!") 5. There are three things wrong with this program. List each. (3 pts) @@ -34,13 +48,16 @@ x = input("Enter a number: ") total = total + i print("The total is:", x) - + The input needs to be added to the total that the user put. The semicolon shouldn't be there. The total shouldn't be only the highest number. 6. Write a program that prints a random integer from 1 to 10 (inclusive). - +from random import randint +print(randint(0,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 +my_number = random.random() * 10 + 1 +print(my_number) 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -48,7 +65,24 @@ * Print the count of the positive entries, the number entries equal to zero, and the number of negative entries. Use an if, elif, else chain, not just three if statements. - +positive_number = 0 +total = 0 +zero_number = 0 +negative_number = 0 +for i in range(7): + number = int(input("Enter a number: ")) + total += number + + if number > 0: + positive_number += 1 + elif number == 0: + zero_number += 1 + else: + negative_number += 1 +print("The total sum of the numbers:", total) +print("There were", positive_number, "positive numbers.") +print("There were", zero_number, "zero numbers.") +print("There were", negative_number, "negative numbers.") 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -56,7 +90,29 @@ using if statements. Don't select from a list, as shown in the chapter. * 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 + +total_heads = 0 +total_tails = 0 +count = 0 + + +while count < 50: + + coin = random.randint(0, 1) + + if coin == 1: + print("Heads") + total_heads += 1 + count += 1 + + elif coin == 0: + print("tails") + total_tails += 1 + count += 1 + +print("You got", total_heads ," heads flipped.") +print("You got", total_tails ," tails flipped.") 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -65,5 +121,36 @@ * 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. - +number = int(input("Enter an number 1-3: ")) +import random + + +play = random.randint(1, 3) + +if play == 1: + print("paper") + +elif play == 2: + print("rock") + +elif play == 3: + print("scissors") +if number == 1 and play == 2: + print("Paper wins!") +elif number == 1 and play == 3: + print("Paper loses!") +elif number == 1 and play == 1: + print("Tie!") +if number == 2 and play == 1: + print("Paper wins!") +elif number == 2 and play == 2: + print("Tie!") +elif number == 2 and play == 3: + print("Rock wins!") +if number == 3 and play == 1: + print("Scissors wins!") +elif number == 3 and play == 2: + print("Rock wins!") +elif number == 3 and play == 3: + print("Tie!") From 6115ca3fded508cc487c0f045ab65a72e875ff66 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 14 Nov 2017 10:13:14 -0600 Subject: [PATCH 04/26] Completed Questions 1-5. --- Worksheets/worksheet_06.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..53f974c 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 06 Worksheet @@ -17,21 +17,23 @@ while x < 10: print(x) x = x + 2 - +It writes out 0-10 and then whatever x is + 2. Print 0, 2, 4, 6, 8, on separate lines. +It printed 0, 2, 4, 6, 8 2. What does this program print out? x = 1 while x < 64: print(x) x = x * 2 - + Guess: all the multiples of 64 in separate lines. + answer:1, 2, 4, 8, 16, 32 3. Why is the and x >= 0 not needed? x = 0 while x < 10 and x >= 0: print(x) x = x + 2 - + X starts out at zero so it won't be greater than ten. It'll always be true. You don't need to check for things that'll always be true or false. 4. What does this program print out? (0 pts) Explain. (1 pt) x = 5 @@ -40,6 +42,7 @@ if x == "1": print("Blast off!") x = x - 1 + It does not print blast off becasue strings and intgers are never equal. Though it does print a countdown from 5 to 0. 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) @@ -48,7 +51,7 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") - + x = float(input("Enter a number greater than zero: ")) 6. Fix the following code: x = 10 From cf555750441bb0168e6e2aca394d897658e9184d Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Wed, 15 Nov 2017 08:04:14 -0600 Subject: [PATCH 05/26] Completed Chapter 6 worksheet. --- Worksheets/worksheet_06.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 53f974c..a9f46c7 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -61,6 +61,7 @@ It printed 0, 2, 4, 6, 8 x - 1 print("Blast-off") +Answer: Change the less than sign to a greater than sign. 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) @@ -69,7 +70,7 @@ It printed 0, 2, 4, 6, 8 for i in range(10): print(i) i += 1 - +Answer: The i += 1 isn't needed in the code. 8. Explain why the values printed for x are so different. (2 pts) # Sample 1 @@ -88,4 +89,4 @@ It printed 0, 2, 4, 6, 8 x += 1 print(x) - +Answer: The reason the values are so different is because the sample 2 has the second for loop within another for loop. From f851b1dac0fef44b4ec53122f7f5f779d686315e Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Wed, 15 Nov 2017 08:53:32 -0600 Subject: [PATCH 06/26] first attempt --- Lab 06 - Loopy Lab/part_1.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..6cfb531 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,15 @@ +#Set a variable to ten +counter = 10 +#Repeat nine times +for i in range(9): + + + #Loop to print numbers in a line + for j in range(i + 1): + print(counter, end=" ") + #increatment the number + counter += 1 + #print new line + print() + From b84bed2e4ee8ae03af1de82b8b08fa6bf1445795 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Wed, 15 Nov 2017 08:56:58 -0600 Subject: [PATCH 07/26] Success --- Lab 06 - Loopy Lab/part_1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 6cfb531..0d7d535 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -10,6 +10,6 @@ print(counter, end=" ") #increatment the number counter += 1 - #print new line - print() + #print new line + print() From b1f9bddfad71672177fb807bc5265ee44d6beb8f Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Wed, 15 Nov 2017 08:59:09 -0600 Subject: [PATCH 08/26] Completed Chapter 6 Lab part 1 --- Lab 06 - Loopy Lab/part_1.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 0d7d535..3ecb0e1 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -12,4 +12,3 @@ counter += 1 #print new line print() - From 94e9171a44794be1f0364d85cdbc2bd3ade2c7ff Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Wed, 15 Nov 2017 09:22:04 -0600 Subject: [PATCH 09/26] Forgot to do a commit but Completed Chapter 6 Lab part 2 --- Lab 06 - Loopy Lab/part_2.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..92dce1a 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,17 @@ -# +#Do an input statement to make box any size user wants +n = int(input("Desired size: ")) + +#Variable for spaces +spaces = (n*2) - 2 + +#print the o times the variable and times 2 +print('o' * ((n)*2)) + +#loop variable - 1 +for i in range(1, n-1): + +#print the o's + spaces times and then plus another o + print('o' + (' '*spaces) + 'o') + +#print the final row of o's times the variable and 2. +print('o'*(n)*2) From 38f5b2950dde6672879092e9734bb3eea5bcd067 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 16 Nov 2017 08:48:04 -0600 Subject: [PATCH 10/26] Completed worksheet 5 --- Worksheets/worksheet_05.txt | 45 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..d62e601 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 05 Worksheet @@ -7,22 +7,23 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. - +The computer has the y coordinates reversed compared to the cartesian. The cartestian focuses on the upper right quadrantt. The computer figures out what is off screen so the programmer doesn't need to worry about it. 2. Before a Python Pygame program can use any functions like pygame.display.set_mode(), what two lines of code must occur first? - +It must have import pygame then pygame.init() and then size = (100, 700) 3. Explain how WHITE = (255, 255, 255) represents a color. - +White represents the presence of all colors in equal amounts. 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.) - +In upper case when the variable won't change regardless of change. +And we use lower case when the variable CAN change such as sky_color. 5. What does the pygame.display.set_mode() function do? - +pygame displays what the user did. 6. What does this for event in pygame.event.get() loop do? - +It tells what the user did. 7. What is pygame.time.Clock used for? - + It displays the current time on the screen. 8. For this line of code: (3 pts) pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5) @@ -31,39 +32,43 @@ * What does [0, 0] do? * What does [100, 100] do? * What does 5 do? - +Screen: Draws a line from the 0, 0 to 100, 100. +[0, 0] tells where the line starts from. +[100, 100] tells where the line is going to end at. +5 tells how many pixels wide it'll be while using a loop. 9. What is the best way to repeat something over and over in a drawing? - +Have the y_offset to zero. Set y_offset to increase by ten each time. 10. When drawing a rectangle, what happens if the specified line width is zero? - +The line won't show up. 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? - - +x, y is (20, 20). +The origin coordinates specify the four numbers if the order of (x, y, width, height). +The length and width of the ellipse is the first two numbers in the order. pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) 12. When drawing an arc, what additional information is needed over drawing an ellipse? - +When drawing an arc over an ellipse it needs radians to determine what the angle to draw is. 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? - +The program to create a variable to hold the info. Second an image of the text. Third program tells where the omage of the text should be placed. 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. - +So as to prevent the text from being repeated an infinite number of times. 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) - +The coordinates are at 50, 100 0,200 200,200 100,50 and with a width of 5. 16. What does pygame.display.flip() do? - +It updates the screen with what has been drawn so far. 17. What does pygame.quit() do? - +It says the user asked to quit. 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.rect(screen, RED, [55,50,20,25], 5) From 86dba09bf2cb1018e795317832188a80b2f04da7 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 16 Nov 2017 09:00:23 -0600 Subject: [PATCH 11/26] First commit of part 4 --- Lab 06 - Loopy Lab/part_4.py | 64 +++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..c01e78f 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,63 @@ -# +""" + 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 +""" + +import pygame + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) + +pygame.init() + +# Set the width and height of the screen [width, height] +size = (500, 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(WHITE) + + # --- Drawing code should go here +for i in range(10): + for j in range(10): + pygame.draw.rect(screen, RED, [5,5,5,5], 5) + # --- 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() From 112b2905b4883aa2fad0bc9475fd4fd9dd8de82a Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 16 Nov 2017 09:08:30 -0600 Subject: [PATCH 12/26] Trouble with y_offset --- Lab 06 - Loopy Lab/part_4.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index c01e78f..6b7cdf5 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -50,9 +50,13 @@ screen.fill(WHITE) # --- Drawing code should go here -for i in range(10): - for j in range(10): - pygame.draw.rect(screen, RED, [5,5,5,5], 5) + y_offset = 0 + for x in range(10): + y_offset += 5 + x_offset = 5 + for y in range(10): + pygame.draw.rect(screen, RED, [x_offset,y_offset,5,5], 5) + x_offset += 5 # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() From c34d826a5e59e4a1d742185a3b9e2b0f94eb1e59 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 16 Nov 2017 09:11:45 -0600 Subject: [PATCH 13/26] Got it to print little rectangles in a box but not large enough for grid --- Lab 06 - Loopy Lab/part_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 6b7cdf5..66a62ec 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -55,7 +55,7 @@ y_offset += 5 x_offset = 5 for y in range(10): - pygame.draw.rect(screen, RED, [x_offset,y_offset,5,5], 5) + pygame.draw.rect(screen, RED, [5,5,x_offset,y_offset], 5) x_offset += 5 # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() From 29468bd15b949aa53e13b907e9299b46f30fc42f Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Thu, 16 Nov 2017 09:18:14 -0600 Subject: [PATCH 14/26] Completed Chapter 6 part 4 --- Lab 06 - Loopy Lab/part_2.py | 84 ++++++++++++++++++++++++++++-------- Lab 06 - Loopy Lab/part_4.py | 12 +++--- 2 files changed, 73 insertions(+), 23 deletions(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 92dce1a..19790d7 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1,17 +1,67 @@ -#Do an input statement to make box any size user wants -n = int(input("Desired size: ")) - -#Variable for spaces -spaces = (n*2) - 2 - -#print the o times the variable and times 2 -print('o' * ((n)*2)) - -#loop variable - 1 -for i in range(1, n-1): - -#print the o's + spaces times and then plus another o - print('o' + (' '*spaces) + 'o') - -#print the final row of o's times the variable and 2. -print('o'*(n)*2) +""" + 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 +""" + +import pygame + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) + +pygame.init() + +# Set the width and height of the screen [width, height] +size = (500, 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(WHITE) + + # --- Drawing code should go here + y_offset = 0 + for x in range(1, 20): + y_offset += 50 + x_offset = 50 + for y in range(1, 20): + pygame.draw.circle(screen, RED, [x_offset,y_offset], 10, 5) + x_offset += 50 + # --- 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() diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 66a62ec..19790d7 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -51,12 +51,12 @@ # --- Drawing code should go here y_offset = 0 - for x in range(10): - y_offset += 5 - x_offset = 5 - for y in range(10): - pygame.draw.rect(screen, RED, [5,5,x_offset,y_offset], 5) - x_offset += 5 + for x in range(1, 20): + y_offset += 50 + x_offset = 50 + for y in range(1, 20): + pygame.draw.circle(screen, RED, [x_offset,y_offset], 10, 5) + x_offset += 50 # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() From 7c0bba5fb0dfda12926abf32668a1b0278329b30 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Mon, 20 Nov 2017 08:37:23 -0600 Subject: [PATCH 15/26] Completed worksheet of chpater 7. --- Lab 05 - Create a Picture/main_program.py | 2 +- Worksheets/worksheet_07.txt | 70 +++++++++++++++++------ 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..4287ca8 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1 @@ -# +# \ No newline at end of file diff --git a/Worksheets/worksheet_07.txt b/Worksheets/worksheet_07.txt index a87ff3f..540b3e8 100644 --- a/Worksheets/worksheet_07.txt +++ b/Worksheets/worksheet_07.txt @@ -1,4 +1,4 @@ - +Jason Cobb Chapter 07 Worksheet @@ -8,7 +8,10 @@ 1. List the four types of data we've covered, and give an example of each: - +String: type("Hi there") +Integer: type(3) +Floating point: type(3.14) +Boolean: type(True) 2. What does this code print out? For this and the following problems, make sure you understand WHY it prints what it does. You don't have to explain it, but if you don't understand why, make sure to ask. @@ -18,13 +21,13 @@ print(my_list[1]) print(my_list[4]) print(my_list[5]) - +It prints out builtins.IndexError: list index out of range. 3. What does this code print out? my_list=[5, 2, 6, 8, 101] for my_item in my_list: print(my_item) - +It prints out 5, 2, 6, 8, 101 in separate lines. 4. What does this code print out? my_list1 = [5, 2, 6, 8, 101] @@ -33,21 +36,26 @@ print(my_list1) my_list2[2] = 10 print(my_list2) - +builtins.TypeError: 'tuple' object does not support item assignment 5. What does this code print out? my_list = [3 * 5] print(my_list) my_list = [3] * 5 print(my_list) - +It prints out [15] and in another line prints [3, 3, 3, 3, 3]. 6. What does this code print out? my_list = [5] for i in range(5): my_list.append(i) print(my_list) - +[5, 0] +[5, 0, 1] +[5, 0, 1, 2] +[5, 0, 1, 2, 3] +[5, 0, 1, 2, 3, 4] + 7. What does this code print out? print(len("Hi")) @@ -55,48 +63,70 @@ print(len("Hi") + len("there.")) print(len("2")) print(len(2)) - + builtins.TypeError: object of type 'int' has no len() 8. What does this code print out? print("Simpson" + "College") print("Simpson" + "College"[1]) print( ("Simpson" + "College")[1] ) - +SimpsonCollege +Simpsono +i + 9. What does this code print out? word = "Simpson" for letter in word: print(letter) - +S +i +m +p +s +o +n + 10. What does this code print out? word = "Simpson" for i in range(3): word += "College" print(word) - + SimpsonCollege +SimpsonCollegeCollege +SimpsonCollegeCollegeCollege + 11. What does this code print out? word = "Hi" * 3 print(word) - +HiHiHi 12. What does this code print out? my_text = "The quick brown fox jumped over the lazy dogs." print("The 3rd spot is: " + my_text[3]) print("The -1 spot is: " + my_text[-1]) - + The 3rd spot is: +The -1 spot is: . 13. What does this code print out? s = "0123456789" print(s[1]) print(s[:3]) print(s[3:]) - + 1 +012 +3456789 14. Write a loop that will take in a list of five numbers from the user, adding each to an array. Then print the array. Try doing this without looking at the book. - +array = [] +for x in range(5): + user = input("Enter a number: ") + user = int(user) + array.append(user) + print(array) + 15. Write a program that take an array like the following, and print the average. Use the len function, don't just use 15, because that won't work if the list size changes. @@ -104,5 +134,13 @@ Sum the numbers individually as shown in the chapter.) my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] - +my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] + +total = 0 + + +for item in my_list: + total = total + item +average = total / len(my_list) +print(average) From e8fb85bc7ae042a4046d284388cc06dd8bde8cb0 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Mon, 20 Nov 2017 09:29:56 -0600 Subject: [PATCH 16/26] First commit of Lab 7 --- Lab 05 - Create a Picture/main_program.py | 24 ++++++++++++++++++++++- Lab 07 - Adventure/main_program.py | 24 ++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 4287ca8..df03799 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,23 @@ -# \ No newline at end of file +#Create an empty array called room_list +room_list = [] + +#Create a variable called room with an array of five elements. +room = [4] +#First element create a string with description of the first room. + +#Other four will be number of the next room if user goes north, south, east, or west. + +#Make sure to write which number connects to which other. + +#If there isn't one at a location like none at the west then write None but NOT in quotes. + +#Append the room to the room list + +#Repeat the prior two steps for each foom you want to create. + +#Re-use the room variable + +#Make new variable called current_room set it to zero. +current_room = 0 +#print the room_list variable run the program to test it. +print(room_list) \ No newline at end of file diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..df03799 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,23 @@ -# +#Create an empty array called room_list +room_list = [] + +#Create a variable called room with an array of five elements. +room = [4] +#First element create a string with description of the first room. + +#Other four will be number of the next room if user goes north, south, east, or west. + +#Make sure to write which number connects to which other. + +#If there isn't one at a location like none at the west then write None but NOT in quotes. + +#Append the room to the room list + +#Repeat the prior two steps for each foom you want to create. + +#Re-use the room variable + +#Make new variable called current_room set it to zero. +current_room = 0 +#print the room_list variable run the program to test it. +print(room_list) \ No newline at end of file From ae9e9d498841a02fed861ffaad4a8d0d08b952fd Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Mon, 20 Nov 2017 09:31:18 -0600 Subject: [PATCH 17/26] Tried to run program didn't go well --- Lab 07 - Adventure/main_program.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index df03799..0f0e858 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -2,13 +2,19 @@ room_list = [] #Create a variable called room with an array of five elements. -room = [4] +room = ["North hall", "Dining room", "South hall", "Bedroom 1", "Bedroom 2", "Balcony"] #First element create a string with description of the first room. - +First = "North hall" + " Pictures of angels fighting demons line the walls." #Other four will be number of the next room if user goes north, south, east, or west. - +north = 0 +south = 1 +east = 2 +west = 3 #Make sure to write which number connects to which other. - +if user goes west from North hall they will be in the kitchen. +if user goes east from North hall they will be in the Bedroom 1. +if user goes south from North hall they will be in the Bedroom 2. +if user goes north from the North hall they will be None. #If there isn't one at a location like none at the west then write None but NOT in quotes. #Append the room to the room list From 8185a77ffacea73b2aa399062875d636b2568c52 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Mon, 20 Nov 2017 09:52:07 -0600 Subject: [PATCH 18/26] Made the room list so rooms hook up according to the room closest to them. --- Lab 07 - Adventure/main_program.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 0f0e858..b126728 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -2,7 +2,20 @@ room_list = [] #Create a variable called room with an array of five elements. -room = ["North hall", "Dining room", "South hall", "Bedroom 1", "Bedroom 2", "Balcony"] +room = ["North hall", None, 4, 5, 1] +room_list.append(room) +room = ["Kitchen", None, 0, 2, None] +room_list.append(room) +room = ["Dining room", 1, 3, None, None] +room_list.append(room) +room = ["South hall", 0, 5, 6, 2] +room_list.append(room) +room = ["Bedroom 1", None, None, 5, 0] +room_list.append(room) +room = ["Bedroom 2", 4, None, None, 3] +room_list.append(room) +room = ["Balcony", 3, None, None, None] +room_list.append(room) #First element create a string with description of the first room. First = "North hall" + " Pictures of angels fighting demons line the walls." #Other four will be number of the next room if user goes north, south, east, or west. From e7233dbcd5ea03d27e9fda6ee64503d22536da6e Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Mon, 20 Nov 2017 10:03:44 -0600 Subject: [PATCH 19/26] Finished room variable I believe. --- Lab 07 - Adventure/main_program.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index b126728..1987c1e 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -3,6 +3,7 @@ #Create a variable called room with an array of five elements. room = ["North hall", None, 4, 5, 1] +#Append the room to the room list room_list.append(room) room = ["Kitchen", None, 0, 2, None] room_list.append(room) @@ -17,26 +18,11 @@ room = ["Balcony", 3, None, None, None] room_list.append(room) #First element create a string with description of the first room. -First = "North hall" + " Pictures of angels fighting demons line the walls." -#Other four will be number of the next room if user goes north, south, east, or west. -north = 0 -south = 1 -east = 2 -west = 3 -#Make sure to write which number connects to which other. -if user goes west from North hall they will be in the kitchen. -if user goes east from North hall they will be in the Bedroom 1. -if user goes south from North hall they will be in the Bedroom 2. -if user goes north from the North hall they will be None. -#If there isn't one at a location like none at the west then write None but NOT in quotes. - -#Append the room to the room list +First = "North hall" + " Pictures of angels fighting demons line the walls." #Repeat the prior two steps for each foom you want to create. - #Re-use the room variable - #Make new variable called current_room set it to zero. current_room = 0 #print the room_list variable run the program to test it. -print(room_list) \ No newline at end of file +print(room_list[0]) \ No newline at end of file From b63fbeb895ba36d2ede1b2b5679f00f2fa92d8fe Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 28 Nov 2017 08:20:23 -0600 Subject: [PATCH 20/26] Help from teacher and testing. --- Lab 07 - Adventure/main_program.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 1987c1e..3c8ac3c 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -2,7 +2,8 @@ room_list = [] #Create a variable called room with an array of five elements. -room = ["North hall", None, 4, 5, 1] +room = ["North hall pictures of angels fighting demons line the walls.", None, 4, 5, 1] + #Append the room to the room list room_list.append(room) room = ["Kitchen", None, 0, 2, None] @@ -11,18 +12,18 @@ room_list.append(room) room = ["South hall", 0, 5, 6, 2] room_list.append(room) -room = ["Bedroom 1", None, None, 5, 0] -room_list.append(room) -room = ["Bedroom 2", 4, None, None, 3] +room = ["This is our Bedroom 1.", None, None, 5, 0] room_list.append(room) -room = ["Balcony", 3, None, None, None] +room = ["This is the Bedroom 2.", 4, None, None, 3] room_list.append(room) -#First element create a string with description of the first room. -First = "North hall" + " Pictures of angels fighting demons line the walls." +room = ["This is the Balcony.", 3, None, None, None] -#Repeat the prior two steps for each foom you want to create. -#Re-use the room variable #Make new variable called current_room set it to zero. current_room = 0 + #print the room_list variable run the program to test it. -print(room_list[0]) \ No newline at end of file +#print(room_list) + +#Use the current_room and room_list to print which room the user is in. +print("You are in", room_list [current_room][0]) +#Since your first room is zero, the output should be the same as before. From c090f1932543200d2fb218bcee8f54e88e06d138 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 28 Nov 2017 08:23:30 -0600 Subject: [PATCH 21/26] Added descriptions of rooms. --- Lab 07 - Adventure/main_program.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 3c8ac3c..50e0e4f 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -2,21 +2,21 @@ room_list = [] #Create a variable called room with an array of five elements. -room = ["North hall pictures of angels fighting demons line the walls.", None, 4, 5, 1] +room = ["the North hall pictures of angels fighting demons line the walls.", None, 4, 5, 1] #Append the room to the room list room_list.append(room) -room = ["Kitchen", None, 0, 2, None] +room = ["the Kitchen that has pots and pans setup for cooking.", None, 0, 2, None] room_list.append(room) -room = ["Dining room", 1, 3, None, None] +room = ["the Dining room that has plates and silverwear set out.", 1, 3, None, None] room_list.append(room) -room = ["South hall", 0, 5, 6, 2] +room = ["the South hall that has many sets of different armor.", 0, 5, 6, 2] room_list.append(room) -room = ["This is our Bedroom 1.", None, None, 5, 0] +room = ["Bedroom 1 that has a bed, closet, and bathroom.", None, None, 5, 0] room_list.append(room) -room = ["This is the Bedroom 2.", 4, None, None, 3] +room = ["Bedroom 2 that also has a bed, closet, and bathroom.", 4, None, None, 3] room_list.append(room) -room = ["This is the Balcony.", 3, None, None, None] +room = ["the Balcony that oversees the lake behind the castle.", 3, None, None, None] #Make new variable called current_room set it to zero. current_room = 0 From eaa2acfb8058a832732976ef3ec63667c3f038b5 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 28 Nov 2017 08:47:37 -0600 Subject: [PATCH 22/26] Testing --- Lab 07 - Adventure/main_program.py | 36 ++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 50e0e4f..151f6df 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -2,7 +2,7 @@ room_list = [] #Create a variable called room with an array of five elements. -room = ["the North hall pictures of angels fighting demons line the walls.", None, 4, 5, 1] +room = ["the North hall pictures of angels fighting demons line the walls.", None, 4, 3, 1] #Append the room to the room list room_list.append(room) @@ -25,5 +25,37 @@ #print(room_list) #Use the current_room and room_list to print which room the user is in. -print("You are in", room_list [current_room][0]) + #Since your first room is zero, the output should be the same as before. +done = False +while done == False: + print() + print("You are in", room_list [current_room][0]) + answer = input("What do you want to do?: ") + if answer == "n": + next_room = room_list[current_room][1] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + if answer == "e": + next_room = room_list[current_room][2] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + if answer == "s": + next_room = room_list[current_room][3] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + if answer == "w": + next_room = room_list[current_room][4] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room \ No newline at end of file From 2734d8e6802a18bd38d2e13a61939af92cfd5ec8 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 28 Nov 2017 09:00:44 -0600 Subject: [PATCH 23/26] Added room_list.append for balcony --- Lab 07 - Adventure/main_program.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 151f6df..fbe8781 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -17,6 +17,7 @@ room = ["Bedroom 2 that also has a bed, closet, and bathroom.", 4, None, None, 3] room_list.append(room) room = ["the Balcony that oversees the lake behind the castle.", 3, None, None, None] +room_list.append(room) #Make new variable called current_room set it to zero. current_room = 0 @@ -34,27 +35,16 @@ answer = input("What do you want to do?: ") if answer == "n": next_room = room_list[current_room][1] - if next_room == None: - print("You can't go that way.") - else: - current_room = next_room - - if answer == "e": + + elif answer == "e": next_room = room_list[current_room][2] - if next_room == None: - print("You can't go that way.") - else: - current_room = next_room - if answer == "s": + elif answer == "s": next_room = room_list[current_room][3] - if next_room == None: - print("You can't go that way.") - else: - current_room = next_room - if answer == "w": + elif answer == "w": next_room = room_list[current_room][4] + if next_room == None: print("You can't go that way.") else: From 5c73dad833ef9fdd252a35d60b9fa05bac0e0ba4 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 28 Nov 2017 09:38:14 -0600 Subject: [PATCH 24/26] Chopped a bit of the line that was too long. --- Lab 07 - Adventure/main_program.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index fbe8781..d50179a 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -48,4 +48,4 @@ if next_room == None: print("You can't go that way.") else: - current_room = next_room \ No newline at end of file + current_room = next_room \ No newline at end of file From d562e8e493ace4857ef2a2da4cc2d8359af97ba1 Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Tue, 28 Nov 2017 10:09:54 -0600 Subject: [PATCH 25/26] Made a way for the user to exit the program --- Lab 07 - Adventure/main_program.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index d50179a..7a84471 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -29,23 +29,28 @@ #Since your first room is zero, the output should be the same as before. done = False -while done == False: +while not done: print() print("You are in", room_list [current_room][0]) answer = input("What do you want to do?: ") - if answer == "n": + if answer.lower()[0] == "n": next_room = room_list[current_room][1] - elif answer == "e": + elif answer.lower()[0] == "e": next_room = room_list[current_room][2] - elif answer == "s": + elif answer.lower()[0] == "s": next_room = room_list[current_room][3] - elif answer == "w": + elif answer.lower()[0] == "w": next_room = room_list[current_room][4] - + + elif answer.lower()[0] == "q": + break + if next_room == None: print("You can't go that way.") else: - current_room = next_room \ No newline at end of file + current_room = next_room + +print("Have a nice day.") \ No newline at end of file From 794647f6d8254d75654b2f9d458c7ac6960ab79f Mon Sep 17 00:00:00 2001 From: JasonC07 Date: Wed, 29 Nov 2017 08:05:37 -0600 Subject: [PATCH 26/26] Completed Lab 7 --- Lab 07 - Adventure/main_program.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 7a84471..70dd119 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1,3 +1,8 @@ +#!/usr/bin/env python3 +#Adventure.py +#Jason Cobb +#11/28/17 + #Create an empty array called room_list room_list = []