From 1bbff7b47b483fe28ce1c38390b8c81aec06a0c8 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 1 Nov 2017 12:15:07 -0500 Subject: [PATCH 01/33] I made the program --- Lab 01 - Calculator/lab_01_part_a.py | 11 ++++++++++- Lab 01 - Calculator/lab_01_part_a.py.save | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Lab 01 - Calculator/lab_01_part_a.py.save diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..8f63e01 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,10 @@ -# +#!/usr/bin/env/ python3 +# Calculator Part a +# Brady Ballmann +# 11/01/2017 + +fahrenheit = int(input("Enter a tempature in Fahrenheit: ")) + +celcius = (fahrenheit - 32) * 5/9 + +print(celcius) diff --git a/Lab 01 - Calculator/lab_01_part_a.py.save b/Lab 01 - Calculator/lab_01_part_a.py.save new file mode 100644 index 0000000..0ac9f55 --- /dev/null +++ b/Lab 01 - Calculator/lab_01_part_a.py.save @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +# Lab 1: Custom Calculators Part a +# Brady Ballmann +# 11/01/2017 + +fahrenheit = input(' From 800773b747308f3bcde042e103c82590a0a52ded Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 1 Nov 2017 12:31:52 -0500 Subject: [PATCH 02/33] I made the program work --- Lab 01 - Calculator/lab_01_part_a.py | 2 +- Lab 01 - Calculator/lab_01_part_b.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 8f63e01..fd0aa41 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -7,4 +7,4 @@ celcius = (fahrenheit - 32) * 5/9 -print(celcius) +print('The temperature in celcius:', celcius) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..34dd0bd 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,8 @@ -# +print('Area of a trapezoid') +height = int(input("Enter the height of the trapezoid: ")) +length_btm = int(input("Enter the length of the bottom base: ")) +length_top = int(input("Enter the length of the top base: ")) + +area = ((length_btm + length_top) / 2) * height + +print('The area is:', area) From 5ee54cc9e9a8c469fcf4437c4a1aeed8fab052d4 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 1 Nov 2017 12:47:05 -0500 Subject: [PATCH 03/33] Made the program --- Lab 01 - Calculator/lab_01_part_c.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..7e79e0f 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,8 @@ -# +import math + +print('Area of an equilateral triangle') +area_side = int(input('Length of a side: ')) + +area = (math.sqrt(3)/4)*(area_side * area_side) + +print('The Area of the triangle:',area) From 6c322d1ac719c376921f108aba162952ccabef83 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 1 Nov 2017 13:38:47 -0500 Subject: [PATCH 04/33] Answered questions --- Worksheets/worksheet_01.txt | 75 ++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..013fae5 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,23 +6,26 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. + print('Brady Ballmann') 2. How do you enter a comment in a program? + Using a # 3. What do the following lines of code output? ALSO: Why do they give a different answer? print(2 / 3) print(2 // 3) - + 1. Prints .6 repeating + 2. Prints 0 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) - + Because the A variable is captial and the print a is not 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -31,23 +34,25 @@ Area AREA area - area_of_rectangle + area_of_rectangle Area_Of_Rectangle + area_of_rectangle is the best one because it uses _ to replace spaces and lower case letters + 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.) apple - Apple - APPLE - Apple2 - 1Apple - account number - account_number - account.number + Apple + APPLE + Apple2 + 1Apple + account number <--- This one + account_number + account.number <--- This one accountNumber - account# + account# <--- This one pi PI fred @@ -55,21 +60,25 @@ GreatBigVariable greatBigVariable great_big_variable - great.big.variable + great.big.variable <--- This one 2x x2x - total% - #left + total% <--- This one + #left <--- This one 8. Why does this code not work? print(a) a = 45 + because the print statement comes before the variable + 9. Explain the mistake in this code: pi = float(3.14) + It doesnt need to float + 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -79,6 +88,9 @@ area = pi * radius ** 2 print(area) + You could just set pi to 3.14 instead of making x = 3.14 + + 11. Explain the mistake in the following code: x = 4 @@ -86,6 +98,9 @@ a = ((x) * (y)) print(a) + The 3rd line does not need to be seperated by Quotations. + + 12. Explain the mistake in the following code: x = 4 @@ -93,36 +108,58 @@ a = 3(x + y) print(a) + They are not integers + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) + You need an int + 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 ) + They all print the same thing but the 1st one is better to use because it is smaller and keeps the code looking nice :D. + 15. What is a constant? + A variable that doesnt change. + 16. How are variable names for constants different than other variable names? + + You can normally tell when a variable is a constant because they will be in CAPS 17. What is a single quote and what is a double quote? Give and label an example of both. + + "" '' 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('This \r\nis') 19. Can a Python program print text to the screen using single quotes instead of double quotes? + + Yes 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) + Because that is not what you are asking it to do + 21. What is an ``operator'' in Python? + + Symbols that carry out logical computation. + + 22. What does the following program print out? @@ -130,15 +167,19 @@ x + 1 print(x) + 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")) + + print('Your age is', value) From b1eeede8b07147e44faad442a8a0da6cf3935d8e Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Thu, 2 Nov 2017 11:54:46 -0500 Subject: [PATCH 05/33] Answered questions on Chapter 2 --- Worksheets/worksheet_02.txt | 64 ++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..ab2bb2e 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -1,4 +1,4 @@ - +Brady Ballmann Chapter 02 Worksheet @@ -7,36 +7,98 @@ binary, decimal, and hexadecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.) + 1010 + + 2. Give an example of a decimal number. + + 17 3. Give an example of a hexadecimal number. + A + + 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. + 0, 2, 4, 8, 16 + + 5. What is a compiler? + Turns source code into machine code + 6. What is source code? + Code the programmer enters + 7. What is machine language? (Don't just say binary. That's not correct.) + Machine code is what the computer interpretes source code into + 8. What is a first generation language? (Don't just say binary. That's not correct.) + A combination of 0 and 1's to represent numbers + It is the same thing as machine language + + 9. What is a second generation language? + Assembly language that uses a compiler to turn source code into machine code. + 10. What is a third generation language? (Explain, don't just give one example.) + + A high level computer programming language. Like python or C. Turns source code directly into machine code. 11. What is an interpreter and how does it differ from a compiler? + It runs source code and interprets it directly into machine code on the fly. + + It is diffirent because you can not switch between different computing machines like linux and windows. + 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. + This website: https://www.tiobe.com/tiobe-index// + + Top 10: + Java + C + C++ + C# + Python + JavaScript + PHP + Visual Basic .NET + Assembly language + Ruby + + + + + + + + 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. + Most jobs are looking for Java developers. + + https://www.dice.com/jobs?q=Developer&l=Saint+Charles%2C+MO&searchid=9954836866302&stst= + 14. What is the difference between the ``syntax'' and ``semantics'' of a language? + syntax deals with the structure/form of the code + + semantics deal with meaning assigned to that specific symbol, character, or word + + + + 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 has ram and an operating system(ios). The software is like the apps that I run on it. From cc22db6a7ad2c00a66495a4820caca9359e39e43 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Thu, 2 Nov 2017 13:41:56 -0500 Subject: [PATCH 06/33] Answered 1 and 2 --- Worksheets/worksheet_03.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..3325e26 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,10 +10,26 @@ print("It is hot outside.") else: print("It is not hot out.") + + int instead of float 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("This number is positive") +elif number < 0: + print("This number is negative") +elif number == 0: + print("This number is 0") + + + + + + 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) From f87bce774fc7d26e81312eba91a98df8ec0c3c20 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Fri, 3 Nov 2017 11:47:28 -0500 Subject: [PATCH 07/33] Answered questions for Chapter 3 --- Worksheets/worksheet_03.txt | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index 3325e26..561c05d 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -34,6 +34,17 @@ elif number == 0: 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') +else: + print('Wrong') + + + + 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -43,6 +54,8 @@ elif number == 0: print("Correct!") else: print("Incorrect.") + + It ask the question before giving the options to the question. 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. @@ -54,12 +67,18 @@ elif number == 0: print("x is positive.") else: print("x is not positive.") + + In the 1st line you only need 1 Equal sign(=). You should have an input statement instead of setting x to a certain number. 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") + + 1. On the 1st line there is no "int" + 2. On the 2nd line there needs to be a doube == and a : at the end(if x == 3:) + 3. The variable for the number is a bad variable(x) should be like "number" 7. There are four things wrong with this code. Identify all four issues. (4 pts) @@ -68,12 +87,25 @@ elif number == 0: print("Correct!") else print("Incorrect! It is Beaker.") + + 1. Line 2 needs double = + 2. else doesnt have a : + 3. else needs to be indented correctly (lined up with the if statement all the way to the left) + 4.Print is not indented correctly. + + + 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!") + + It says "That is good to hear!" no matter what. You need to add on the right side of line 2 next to "Glad" x == "Glad":. (Line should look like this. + if x == "Happy" or x == "Glad":_) + + 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. @@ -94,6 +126,13 @@ elif number == 0: print("Fizz") if z: print("Buzz") + + Guess:Will print true and false statements. + + Answer: It ran x = 5, y = true, and z = true also printed Buzz because z was true. If you set y to == 5 it would also print Fizz. + + + 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) @@ -113,6 +152,34 @@ elif number == 0: print(x == 5 and y == 5) print(x == 5 or y == 5) + + Guess: False + True + True + False + False + True + False + False + True + False + True + + 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) @@ -126,6 +193,26 @@ elif number == 0: print( (2 == 2) == True ) print(3 < "3") + + Guess: True + False + True + True + False + False + True + True + False + Answer: True +False +True +True +True +False +False +True +error + 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -145,6 +232,12 @@ elif number == 0: money = 70 else if user_input = C: money = 50 + + Well there is multiple things wrong. + + The else if needs to be a elif statement. + The "= B: needs to have " " around the B same goes with A and C + and you need to print the money amount so the user can see how much money.(Optional) From a452fc3bd84c50decfc561fb5cd67e1c7bcf2daa Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Fri, 3 Nov 2017 12:36:21 -0500 Subject: [PATCH 08/33] Chapter 3 Main_program --- Lab 03 - Create a Quiz/main_program.py | 70 +++++++++++++++++++++++++- 1 file changed, 69 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..96d0fb0 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,69 @@ -# +#!/usr/bin/env python3 +# Creating a quiz +# Brady Ballmann +# 11/03/2017 + +percentage = 0 + +print('Ready for a quiz? :)') + +question_one = input('Who won the 2017 World Series? ') +if question_one.lower() == "astros": + print("Correct!") + percentage += 1 +else: + print('Incorrect!') + +question_two = int(input("What is 5 * 432 / 4? ")) +if question_two == 540: + print("Correct!") + percentage += 1 +else: + print("Incorrect!") + +print("What is the most common male name in the US?") +print("1. James") +print("2. Robert") +print("3. David") +print("4. Michael") +print("TIP! Enter the number not the name") +question_three = int(input('? ')) +if question_three == 1: + print('Correct!') + percentage += 1 +else: + print("Incorrect!") + + +question_four = int(input("What is 10 to the power of 3? ")) +if question_four == 1000: + print("Correct!") + percentage += 1 +else: + print("Incorrect!") + +print('If an apple weighs about 3 and 1/2 ounces. What is the radius of the sun? ') +print("1. 432,288 mi") +print("2. 542,421 mi") +print("3. 674,321 mi") +print("4. 132,424 mi") +print("TIP! Enter the number not the name.") +question_five = int(input('? ')) +if question_five == 1: + print('Correct!') + percentage += 1 +else: + print("Incorrect!") + +percent = percentage * 20 +print("You got" , percentage, "out of 5") +print(percent, "percent! Congrats!") + + + + + + + + + From 41269b0b8b4b76aa93a6d193eaf15b68e82a7b8a Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 7 Nov 2017 11:01:36 -0600 Subject: [PATCH 09/33] Answered worksheet_04 --- Worksheets/worksheet_04.txt | 107 +++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..086106b 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,19 +13,51 @@ 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 in range(10): + print("Brady") + 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(5): + 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. - - 5. There are three things wrong with this program. List each. (3 pts) + + i = 10 + while i > -1: + print(i) + i -= 1 + print("Blast off!") + + + + + + + + + + 5.What three things are wrong with this program. List each. (3 pts) print("This program takes three numbers and returns the sum.") total = 0 @@ -34,13 +66,28 @@ x = input("Enter a number: ") total = total + i print("The total is:", x) + + + 1. Line 4 the x needs to be total. + 2. Line 3 I changed it to total += x + 3. Line 2 you need "int" on the input statement. x = int(input("Enter a number: ") 6. Write a program that prints a random integer from 1 to 10 (inclusive). + + import random + random_number = random.randrange(1,11) + print(random_number) + + 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 + random_number = random.random() * 10 + print(random_number) + 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -49,6 +96,35 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. +total = 0 +count_pos = 0 +count_neg = 0 +count_zero = 0 +for i in range(7): + new_number = int(input("Enter a number: " )) + if new_number < 0: + count_neg += 1 + elif new_number > 0: + count_pos += 1 + elif new_number == 0: + count_zero += 1 + + + total += new_number + +print("The total is: ", total) +print(count_neg, "Negative numbers entered") +print(count_pos,"Positive numbers entered") +print(count_zero, "Zeros entered") + + + + + + + + + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +133,25 @@ * 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 +heads = 0 +tails = 0 +for i in range(50): + rand_number = random.randrange(0, 2) + if rand_number == 1: + print("Heads") + heads += 1 + else: + print("Tails") + tails += 1 +print(tails, "Tails") +print(heads, "Heads") + + + + + + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -67,3 +162,9 @@ * Add conditional statement to figure out who wins. + + + + + + From 1a0498379952f113ef4e6331b4cf9dae2da905b7 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 7 Nov 2017 11:08:13 -0600 Subject: [PATCH 10/33] Answered worksheet_04.txt --- Worksheets/worksheet_04.txt | 41 ++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 086106b..b0d9335 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -161,7 +161,46 @@ print(heads, "Heads") * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. - +import random + + +person_input = int(input("Choose between Rock(1),Paper(2) or, Scissors(3): ")) +if person_input == 3: + print("Scissors") +elif person_input == 2: + print("Paper") +else: + print("Rock") + +rand_number = random.randrange(0, 3) +if rand_number == 1: + print("Rock") +elif rand_number == 2: + print("Paper") +elif rand_number == 0: + print("Scissors") + +if person_input == 3 and rand_number == 2: + print("You win!") +elif person_input == 3 and rand_number == 1: + print("You lose!") +elif person_input == 3 and rand_number == 0: + print("Tie!") + + +elif person_input == 2 and rand_number == 2: + print("Tie!") +elif person_input == 2 and rand_number == 1: + print("You win!") +elif person_input == 2 and rand_number == 0: + print("You lose!") + +elif person_input == 1 and rand_number == 2: + print("You lose!") +elif person_input == 1 and rand_number == 1: + print("Tie!") +elif person_input == 1 and rand_number == 0: + print("You win!") From 4ec0c517c23f1a8671b0d97f55c267e867181cd9 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 7 Nov 2017 12:46:53 -0600 Subject: [PATCH 11/33] Lab for chapter 4 --- Lab 04 - Camel/main_program.py | 85 +++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..9ff40cf 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,84 @@ -# +#!/usr/bin/env python3 +# Camel game +# Brady Ballmann +# November 6th 2017 + +import random + +print("Welcome to Camel!") +print("You have stolen a camel to make your way across the great Mobie desert.") +print("The natives want their camel back and are chasing you down! Survive your") +print("desert trek and out run the natives.") + +done = False +camel_thirst = 0 +camel_tired = 0 +miles_traveled = 0 +distance_natives = -20 +drinks_canteen = 3 + + +random_oasis = random.randrange(1 , 21) + +random_forward = random.randrange(10 , 21) + +random_native = random.randrange(7 , 15) + +random_tiredness = random.randrange(1 , 4) + +random_moderate = random.randrange(5, 13) + + +while not done: +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.") +print() +user_answer = input("Your choice? ") +if user_answer.upper() == "Q": + done = True +elif user_answer.upper() == "E": + print("Miles traveled:", miles_traveled) + print("Drinks in canteen: ", drinks_canteen) + print("The natives are", str(distance_natives) + " miles behind you") +elif user_answer.upper() == "D": + camel_tired = 0 + print("The camel is happy :D") + distance_natives = distance_natives + random_native +elif user_answer.upper() == "C": + miles_traveled = miles_traveled + random_forward + print("You traveled", str(miles_traveled) + " miles.") + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + random_tiredness + distance_natives = distance_natives + random_native +elif user_answer.upper() == "B": + print("You traveled", str(random_moderate) + " miles.") + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + 1 + distance_natives = distance_natives + random_native +elif user_answer.upper() == "A": + drinks_canteen = drinks_canteen - 1 + camel_thirst = 0 +elif not done and camel_thirst < 4: + print("You are thirsty") +elif not done and camel_thirst < 6: + print("You died") + done = True +elif camel_tired > 5: + print("Your camel is getting tired") +elif camel_tired > 8: + print("Your camel is dead") + done = True +elif distance_natives >= miles_traveled: + print("The natives have caught you") + done = True +elif miles_traveled >= 200: + print("YOU WON!") +elif random_oasis == 10: + print("You found an oasis") + drink_canteen = 3 + camel_thirst = 0 + camel_tired = 0 From 4d34b74f5b5716c56c93fe910459db682573d87e Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 8 Nov 2017 12:23:19 -0600 Subject: [PATCH 12/33] Chapter 4 Lab 4 (new and fixed) --- Lab 04 - Camel/main_program.py | 110 ++++++++++++++++----------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 9ff40cf..2456b27 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1,8 +1,3 @@ -#!/usr/bin/env python3 -# Camel game -# Brady Ballmann -# November 6th 2017 - import random print("Welcome to Camel!") @@ -30,55 +25,56 @@ while not done: -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.") -print() -user_answer = input("Your choice? ") -if user_answer.upper() == "Q": - done = True -elif user_answer.upper() == "E": - print("Miles traveled:", miles_traveled) - print("Drinks in canteen: ", drinks_canteen) - print("The natives are", str(distance_natives) + " miles behind you") -elif user_answer.upper() == "D": - camel_tired = 0 - print("The camel is happy :D") - distance_natives = distance_natives + random_native -elif user_answer.upper() == "C": - miles_traveled = miles_traveled + random_forward - print("You traveled", str(miles_traveled) + " miles.") - camel_thirst = camel_thirst + 1 - camel_tired = camel_tired + random_tiredness - distance_natives = distance_natives + random_native -elif user_answer.upper() == "B": - print("You traveled", str(random_moderate) + " miles.") - camel_thirst = camel_thirst + 1 - camel_tired = camel_tired + 1 - distance_natives = distance_natives + random_native -elif user_answer.upper() == "A": - drinks_canteen = drinks_canteen - 1 - camel_thirst = 0 -elif not done and camel_thirst < 4: - print("You are thirsty") -elif not done and camel_thirst < 6: - print("You died") - done = True -elif camel_tired > 5: - print("Your camel is getting tired") -elif camel_tired > 8: - print("Your camel is dead") - done = True -elif distance_natives >= miles_traveled: - print("The natives have caught you") - done = True -elif miles_traveled >= 200: - print("YOU WON!") -elif random_oasis == 10: - print("You found an oasis") - drink_canteen = 3 - camel_thirst = 0 - camel_tired = 0 + 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.") + print() + user_answer = input("Your choice? ") + if user_answer.upper() == "Q": + done = True + elif user_answer.upper() == "E": + print("Miles traveled:", miles_traveled) + print("Drinks in canteen: ", drinks_canteen) + print("The natives are", str(distance_natives) + " miles behind you") + elif user_answer.upper() == "D": + camel_tired = 0 + print("The camel is happy :D") + distance_natives = distance_natives + random_native + elif user_answer.upper() == "C": + miles_traveled = miles_traveled + random_forward + print("You traveled", str(miles_traveled) + " miles.") + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + random_tiredness + distance_natives = distance_natives + random_native + elif user_answer.upper() == "B": + print("You traveled", str(random_moderate) + " miles.") + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + 1 + distance_natives = distance_natives + random_native + elif user_answer.upper() == "A": + drinks_canteen = drinks_canteen - 1 + camel_thirst = 0 + elif not done and camel_thirst < 4: + print("You are thirsty") + elif not done and camel_thirst < 6: + print("You died") + done = True + elif camel_tired > 5: + print("Your camel is getting tired") + elif camel_tired > 8: + print("Your camel is dead") + done = True + elif distance_natives >= miles_traveled: + print("The natives have caught you") + done = True + elif miles_traveled >= 200: + print("YOU WON!") + elif random_oasis == 10: + print("You found an oasis") + drink_canteen = 3 + camel_thirst = 0 + camel_tired = 0 + From e38dd05b3290903296207546867038edb026afb1 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Thu, 9 Nov 2017 12:13:11 -0600 Subject: [PATCH 13/33] Chapter 05 Worksheet --- Worksheets/worksheet_05.txt | 118 ++++++++++++++++++++++++++++++++---- 1 file changed, 106 insertions(+), 12 deletions(-) diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..8b5da89 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -8,62 +8,156 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + 1.(0,0) the origin starts at the top left instead of the middle. + 2. The y coordinate is reversed as y goes up it goes down. + + 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 and pygame.init() + + + + + + 3. Explain how WHITE = (255, 255, 255) represents a color. - + + It appears white for the backround usually + + + 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.) - + + Because it is a constant. When we want to change the value of the color we use lower case. + + + + + 5. What does the pygame.display.set_mode() function do? + + It opens the screen. + 6. What does this for event in pygame.event.get() loop do? + + That is for if the user does something in the program like clicking. + + 7. What is pygame.time.Clock used for? + + Used to manage how fast the screen updates. + 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? It make sure that it draws it on the screen. Initialize + * What does [0, 0] do? Makes the starting point 0,0 + * What does [100, 100] do? Thats the end point. + * What does 5 do? 5 pixels wide + + + 9. What is the best way to repeat something over and over in a drawing? + Drawing it with a loop or offset + Use this code to draw multiple lines + y_offset = 0 + while y_offset < 100: + pygame.draw.line(screen,RED,[0,10+y_offset],[100,110+y_offset],5) + y_offset = y_offset + 10 + + + 10. When drawing a rectangle, what happens if the specified line width is zero? - + Nothing will appear + + + + 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 + * What does the origin coordinate specify? The center of the circle? It is the upper left like a rectangle but with no corners. + * What is the length and the width of the ellipse? 250 pixels wide and 100 tall. pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) 12. When drawing an arc, what additional information is needed over drawing an ellipse? + + + It includes the start and end angles for the arc to draw. 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + + 1.Create a variable that holds the information + + 2. The program creates an image of the text. + + 3. Tell the program where to put the image. Like a stamp. + + + 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. + + Because if you keep it in the loop it will just keep drawing it over and over again. + + + + + 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) + these are the 4 points [50,100],[0,200],[200,200],[100,50] + + + + + + 16. What does pygame.display.flip() do? - + + It updates the screen with what we have drawn so far. It must happen after all drawing commands have been executed or else you will not see them on the scree. + + 17. What does pygame.quit() do? - + When you exit the screen no error will pop up. + + + 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, (20,20), 20,0) + + + + + + + + + + + + + + From 7e4be7dbe3ec9b5e3fbb8dd77661918c26248507 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Thu, 9 Nov 2017 12:21:59 -0600 Subject: [PATCH 14/33] Started to write the program --- Lab 05 - Create a Picture/main_program.py | 52 ++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..1d203b7 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,51 @@ -# +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 = (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(WHITE) + + + + # --- 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 9c67dd0c487477e2dca3ced69d43ab09eadea226 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Thu, 9 Nov 2017 13:24:55 -0600 Subject: [PATCH 15/33] Finishes chapter 05 lab added trees sky and person --- Lab 05 - Create a Picture/main_program.py | 68 ++++++++++++++++++++++- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 1d203b7..ddcf3b5 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1,10 +1,21 @@ +#!/usr/bin/env python3 +# main_program for chapter 5 lab +# Brady Ballmann +# 11/09/2017 + + import pygame # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) -GREEN = (0, 255, 0) +BLUE = (0, 0, 255) +GREEN = (0, 100, 0) RED = (255, 0, 0) +YELLOW = (255, 255, 0) +SKY = (135, 206, 250) +BROWN = (139,69,19) +WHEAT = (245,222,179) pygame.init() @@ -36,8 +47,59 @@ # If you want a background image, replace this clear with blit'ing the # background image. - screen.fill(WHITE) - + screen.fill(SKY) + + # These are Lines and they are the tree + pygame.draw.line(screen, BROWN, [10, 600], [10, 400], 10) + + pygame.draw.line(screen, BROWN, [85, 600], [85, 400], 10) + + pygame.draw.line(screen, BROWN, [160, 600], [160, 400], 10) + + pygame.draw.line(screen, WHEAT, [300, 470], [300, 400], 5) + + pygame.draw.line(screen, WHEAT, [300, 470], [270, 600], 5) + + pygame.draw.line(screen, WHEAT, [300, 470], [350, 600], 5) + + pygame.draw.line(screen, WHEAT, [275, 440], [325, 440], 5) + + pygame.draw.line(screen, BROWN, [690, 600], [690, 400], 10) + + pygame.draw.line(screen, BROWN, [625, 600], [625, 400], 10) + + pygame.draw.line(screen, BROWN, [550, 600], [550, 400], 10) + + pygame.draw.line(screen, BLACK, [375, 600], [375, 475], 7) + + pygame.draw.line(screen, BLACK, [450, 600], [450, 475], 7) + + pygame.draw.line(screen, BLACK, [375, 475], [450, 475], 5) + + + + + # Circles + + pygame.draw.circle(screen, GREEN, (20,350), 65,0) + + pygame.draw.circle(screen, GREEN, (90,350), 65,0) + + pygame.draw.circle(screen, GREEN, (160,350), 65,0) + + pygame.draw.circle(screen, WHEAT, (300,400), 20,0) + + pygame.draw.circle(screen, WHITE, (295,395), 3,0) + + pygame.draw.circle(screen, WHITE, (305,395), 3,0) + + pygame.draw.circle(screen, GREEN, (690,350), 65,0) + + pygame.draw.circle(screen, GREEN, (620,350), 65,0) + + pygame.draw.circle(screen, GREEN, (550,350), 65,0) + + pygame.draw.circle(screen, YELLOW, (20,20), 80,0) # --- Go ahead and update the screen with what we've drawn. From a47b901047d89ca24375bb0c30158a2ee4785ce6 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 14 Nov 2017 11:57:58 -0600 Subject: [PATCH 16/33] Made * table --- Lab 06 Loopy Lab/temp.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Lab 06 Loopy Lab/temp.py b/Lab 06 Loopy Lab/temp.py index 792d600..9d4ae25 100644 --- a/Lab 06 Loopy Lab/temp.py +++ b/Lab 06 Loopy Lab/temp.py @@ -1 +1,13 @@ -# +#!/usr/bin/env python3 +# Loops +# Brady Ballmann +# 11/13/2017 + +# Do 9 times starting at 1 +for row in range(1, 10): + # Loop to print multiples + for i in range(1, 10): + print(row * i, end=" ") + # Print new line + print() + From b7992a86aa3827050f43231c8fe89f4e0221d6b1 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 14 Nov 2017 12:24:06 -0600 Subject: [PATCH 17/33] number triangle --- Lab 06 Loopy Lab/temp.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Lab 06 Loopy Lab/temp.py b/Lab 06 Loopy Lab/temp.py index 9d4ae25..d335fa3 100644 --- a/Lab 06 Loopy Lab/temp.py +++ b/Lab 06 Loopy Lab/temp.py @@ -5,9 +5,15 @@ # Do 9 times starting at 1 for row in range(1, 10): - # Loop to print multiples - for i in range(1, 10): - print(row * i, end=" ") - # Print new line + # Loop to print spaces + for space in range(9 - row): + print(" ", end=" ") + # Loop to print digits + for digits in range(1, row + 1): + print(digits, end=" ") + # Loop to print digits2 + for digits2 in range(row -1, 0, -1): + print(digits2, end=" ") + # Print a new line print() From 639c29214ef6ac4b42ad22bb6f0cfedcf5aade3c Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 14 Nov 2017 12:42:42 -0600 Subject: [PATCH 18/33] 3 side triangle thing --- Lab 06 Loopy Lab/temp.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Lab 06 Loopy Lab/temp.py b/Lab 06 Loopy Lab/temp.py index d335fa3..2c0865e 100644 --- a/Lab 06 Loopy Lab/temp.py +++ b/Lab 06 Loopy Lab/temp.py @@ -16,4 +16,12 @@ print(digits2, end=" ") # Print a new line print() - +for row in range(10): + # Print spaces Loop + for space in range(row+1): + print(" ", end=" ") + # Loop to print digits + for digits in range(1,9-row): + print(digits, end=" ") + # Print new line + print() \ No newline at end of file From f0860886112a12cea2efbdc1d8e52d56e310e920 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 14 Nov 2017 12:53:05 -0600 Subject: [PATCH 19/33] Number diamond is complete --- Lab 06 Loopy Lab/temp.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lab 06 Loopy Lab/temp.py b/Lab 06 Loopy Lab/temp.py index 2c0865e..a889645 100644 --- a/Lab 06 Loopy Lab/temp.py +++ b/Lab 06 Loopy Lab/temp.py @@ -23,5 +23,8 @@ # Loop to print digits for digits in range(1,9-row): print(digits, end=" ") + # Loop to print digits2 + for digits2 in range(7-row,0,-1): + print(digits2,end=" ") # Print new line print() \ No newline at end of file From e0b12b7ce6ea0209b74cd6ada385b9c502d193db Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 14 Nov 2017 13:42:06 -0600 Subject: [PATCH 20/33] Problems 1-4 worksheet answers --- Worksheets/worksheet_06.txt | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..ec88e9a 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,14 @@ while x < 10: print(x) x = x + 2 + + + 0 + 2 + 4 + 6 + 8 + 2. What does this program print out? @@ -24,7 +32,12 @@ while x < 64: print(x) x = x * 2 - + 1 + 2 + 4 + 8 + 16 + 32 3. Why is the and x >= 0 not needed? x = 0 @@ -32,6 +45,11 @@ print(x) x = x + 2 + Because 0 is already = to 0 and it is less than 10. + + There is no way x can go down in value in this loop. + + 4. What does this program print out? (0 pts) Explain. (1 pt) x = 5 @@ -40,6 +58,20 @@ if x == "1": print("Blast off!") x = x - 1 + + 5 + 4 + 3 + 2 + 1 + 0 + + Does not print out blast off because x is == to the character 1. + + + + + 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) @@ -49,6 +81,10 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") + + + + 6. Fix the following code: x = 10 From e3ea8d34a6e1347ae41c7751d375d3079f8ded85 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 15 Nov 2017 11:27:27 -0600 Subject: [PATCH 21/33] Created the triangle --- Lab 06 - Loopy Lab/part_1.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..86b4364 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,6 @@ - +start = 10 +for row in range(10): + for column in range(row+1): + print(start ,end=" ") + start+=1 + print() From c4e81d23bccf37f59722304ccb7fd1b5f508b243 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 15 Nov 2017 11:48:18 -0600 Subject: [PATCH 22/33] Finished questions 5-8 and worksheet is done. Worksheet_06 --- Worksheets/worksheet_06.txt | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index ec88e9a..4d94fc7 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -80,7 +80,13 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") - + + + +ANSWER: x = float(input("Enter a number greater than zero: ")) + while x <= 0: + x = int(input("Too small. Enter a number greater than zero: ")) + You need to add an input and int on the statement in the while loop. Also set it to x @@ -95,6 +101,19 @@ print("Blast-off") + + ANSWER: + + x = 10 + + while x > 0: + print(x) + x = x - 1 + if x == 0: + 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) @@ -102,6 +121,12 @@ for i in range(10): print(i) i += 1 + + + You don't need to set i to 0 because in range it will start at 0 automatically. Also you don't need the i += 1 because the for loop does that already. + + + 8. Explain why the values printed for x are so different. (2 pts) @@ -113,6 +138,7 @@ x += 1 print(x) + # Sample 2 x = 0 for i in range(10): @@ -121,4 +147,12 @@ x += 1 print(x) + + Because the second one has a nester for loop so it will go through way more times than than the one above. + + + + + + From 9045524f0f83b6d12e4e4cceea88555d851c3195 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 15 Nov 2017 12:09:59 -0600 Subject: [PATCH 23/33] Finished part_1 --- Lab 06 - Loopy Lab/part_1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 86b4364..298e58c 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1,5 +1,5 @@ start = 10 -for row in range(10): +for row in range(9): for column in range(row+1): print(start ,end=" ") start+=1 From 5a11682141bfd8ce963348f6469482738272bd45 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 15 Nov 2017 12:14:33 -0600 Subject: [PATCH 24/33] Made the top row for the boxes --- Lab 06 - Loopy Lab/part_2.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..ce9ac74 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,15 @@ -# +#!/usr/bin/env python3 +# part_2 of chapter 6 Lab +# Brady Ballmann +# 11/15/2017 + +# Input statement for the o's +numberos = int(input("How many o's do you want? ")) + +number = numberos * 2 +# Loop for the top of the box +for row in range(number): + print("o",end="") + # + + From c5a168d417d1cec7af7c2cc2b76431faf4179c67 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 15 Nov 2017 12:20:21 -0600 Subject: [PATCH 25/33] Printed one of the sides for the boxes --- Lab 06 - Loopy Lab/part_2.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index ce9ac74..5cd42be 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -8,8 +8,11 @@ number = numberos * 2 # Loop for the top of the box -for row in range(number): +for row in range(number -1 ): print("o",end="") - # + # Loop to print the sides +for column in range(numberos): + print("o") + From 9a5c9353b57a3f0263f4229aadd72328a0811507 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 15 Nov 2017 13:16:51 -0600 Subject: [PATCH 26/33] Completed chapter 06 Lab part 2 --- Lab 06 - Loopy Lab/part_2.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 5cd42be..da84f5b 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -6,13 +6,12 @@ # Input statement for the o's numberos = int(input("How many o's do you want? ")) -number = numberos * 2 -# Loop for the top of the box -for row in range(number -1 ): - print("o",end="") - # Loop to print the sides -for column in range(numberos): - print("o") - +# Print for the top of the box +print('o'*(numberos*2 )) +# Loop for the spaces +for i in range(numberos -2): + print("o" + ' '*(numberos*2 -2 ) + 'o') +# Print the bottom o's +print('o'*(numberos*2)) From 438e642346fc326487da13b4d18a4cbae9211b58 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Thu, 16 Nov 2017 11:46:28 -0600 Subject: [PATCH 27/33] Completed chapter 06 lab --- Lab 06 - Loopy Lab/part_4.py | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..2b349a8 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,78 @@ -# +""" + Simple graphics demo + + Sample Python/Pygame Programs + Simpson College Computer Science + http://programarcadegames.com/ + http://simpson.edu/computer-science/ + +""" + +# Import a library of functions called 'pygame' +import pygame +import random + +# Initialize the game engine +pygame.init() + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +BLUE = (0, 0, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) +YELLOW = (255, 255, 0) +SKY = (135, 206, 250) +BROWN = (139,69,19) +PI = 3.141592653 + + +# Set the height and width of the screen +size = (700, 500) +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("Professor Craven's Cool Game") + +# Loop until the user clicks the close button. +done = False +clock = pygame.time.Clock() + +# Loop as long as done == False +while not done: + + for event in pygame.event.get(): # User did something + if event.type == pygame.QUIT: # If user clicked close + done = True # Flag that we are done so we exit this loop + + # All drawing code happens after the for loop and but + # inside the main while not done loop. + + # Clear the screen and set the screen background + screen.fill(BLACK) + + + for y in range(0,500,10): + for x in range(0,700,10): + pygame.draw.rect(screen, GREEN, [x,y, 5, 5], 0) + print() + + + + + + + + + + # Go ahead and update the screen with what we've drawn. + # This MUST happen after all the other drawing commands. + pygame.display.flip() + + # This limits the while loop to a max of 60 times per second. + # Leave this out and we will use all CPU we can. + clock.tick(60) + +# Be IDLE friendly +pygame.quit() + + From f8327675bf9327aea35e3359149aa6cae75d7290 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Mon, 20 Nov 2017 11:52:50 -0600 Subject: [PATCH 28/33] Finished chapter 07 Worksheet --- Worksheets/worksheet_07.txt | 120 +++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git a/Worksheets/worksheet_07.txt b/Worksheets/worksheet_07.txt index a87ff3f..a56dd4e 100644 --- a/Worksheets/worksheet_07.txt +++ b/Worksheets/worksheet_07.txt @@ -9,6 +9,17 @@ 1. List the four types of data we've covered, and give an example of each: + String: String of characters or text("Hello World") + + Integer: A whole number(4,2,1,3,9, ect.. ) + + Floating point: A number with a decimal point.(1.32313131) + + Boolean: Two values either true or false(done = 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. @@ -19,11 +30,32 @@ print(my_list[4]) print(my_list[5]) + 2 + 101 + 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) + + All the items. + 5 + 2 + 6 + 8 + 101 + + + + + 4. What does this code print out? @@ -34,6 +66,9 @@ my_list2[2] = 10 print(my_list2) + It wont work because you are trying to change a tuple + + 5. What does this code print out? my_list = [3 * 5] @@ -41,6 +76,10 @@ my_list = [3] * 5 print(my_list) + [15] + [3,3,3,3,3] + + 6. What does this code print out? my_list = [5] @@ -48,6 +87,12 @@ my_list.append(i) print(my_list) + [5,0,1,2,3,4] + + + + + 7. What does this code print out? print(len("Hi")) @@ -56,17 +101,39 @@ print(len("2")) print(len(2)) + 2 + 9 + 8 + 1 + Last one doesn't print because 2 is not a character. It is an Integer + 8. What does this code print out? print("Simpson" + "College") print("Simpson" + "College"[1]) print( ("Simpson" + "College")[1] ) + SimpsonCollege + Simsono + 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? @@ -75,17 +142,27 @@ word += "College" print(word) + SimsonCollegeCollegeCollege + + + + + 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" @@ -93,16 +170,55 @@ print(s[:3]) print(s[3:]) + 1 + 01234567893456789 + + 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. + + user_list = [] + for i in range(5): + user_input = int(input( "Enter an integer: ")) + user_list.append(user_input) + print(user_list) + + + + + + 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. (There is a sum function I haven't told you about. Don't use that. - Sum the numbers individually as shown in the chapter.) + 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] + + + list_total = 0 + + + + for i in range(len(my_list)): + + list_total += my_list[i] + + + averagelist = list_total / len(my_list) + + print(averagelist) + + + + + + + - my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] From c8ae09f37a78cf001ad78bb221e9e85d6603518b Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Mon, 20 Nov 2017 12:57:13 -0600 Subject: [PATCH 29/33] Finished while loop and appending room_list --- Lab 07 - Adventure/main_program.py | 64 +++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..53ab44f 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,63 @@ -# +#!/usr/bin/env python3 +# main_program chapter 07 +# Brady Ballmann +# 11/20/2017 + +room_list = [] + + + +room = ["You are in a entrance room. There is a passage to the north",1,None,None,None] + +room_list.append(room) + +room = ["You are in the Diner. There is a passage way to the north, east, and south",4,2,0,None] + +room_list.append(room) + +room = ["You are in the balcony hall. There is a passage way to the north and south",4,None,1,None] + +room_list.append(room) + +room = ["You are in the bedroom hallway. There is a passage way to the East and West",None,3,None,1] + +room_list.append(room) + +room = ["You are in the bedroom. There is a passage way to the North and West",8,None,None,2] + +room_list.append(room) + +room = ["You are in the hallway between the bathroom and the bedroom. There is a passage way to the north and south",3,None,7,None] + +room_list.append(room) + +room = ["You are in the Bathroom. There is a passage way to the South and West",None,None,8,6] + +room_list.append(room) + +room = ["You are in the hallway between the balcony and the bathroom. There is a passage way to the East and West",None,7,None,5] + +room_list.append(room) + +room = ["You are outside on the balcony. There is a passage way to the South and East",None,6,4,None] + +room_list.append(room) + +room = ["You are in the hallway between the diner and the balcony. There is a passage way to the north and south",5,None,1,None] + +room_list.append(room) + +current_room = 0 + + + +done = False + +while not done: + print() + print(room_list[current_room][0]) + user_direction = print(input("What direction would you like to go? ")) + print() + if user_direction == "n": + print("hi") + \ No newline at end of file From cd5ba0a0d35c7ff9040f811b45f28dfa57515957 Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 28 Nov 2017 11:54:23 -0600 Subject: [PATCH 30/33] Fixed the hardcoding of telling the direction --- Lab 07 - Adventure/main_program.py | 32 +++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 53ab44f..2853fcd 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -6,46 +6,40 @@ room_list = [] - +# 0 room = ["You are in a entrance room. There is a passage to the north",1,None,None,None] room_list.append(room) - -room = ["You are in the Diner. There is a passage way to the north, east, and south",4,2,0,None] - -room_list.append(room) - -room = ["You are in the balcony hall. There is a passage way to the north and south",4,None,1,None] +# 1 +room = ["You are in the Diner. There is a passage way to the east, and south",None,2,0,None] room_list.append(room) +# 3 room = ["You are in the bedroom hallway. There is a passage way to the East and West",None,3,None,1] room_list.append(room) - +# 4 room = ["You are in the bedroom. There is a passage way to the North and West",8,None,None,2] room_list.append(room) - +# 5 room = ["You are in the hallway between the bathroom and the bedroom. There is a passage way to the north and south",3,None,7,None] room_list.append(room) - +# 6 room = ["You are in the Bathroom. There is a passage way to the South and West",None,None,8,6] room_list.append(room) - +# 7 room = ["You are in the hallway between the balcony and the bathroom. There is a passage way to the East and West",None,7,None,5] room_list.append(room) - -room = ["You are outside on the balcony. There is a passage way to the South and East",None,6,4,None] +# 8 +room = ["You are outside on the balcony. There is a passage way to the East",None,None,4,None] room_list.append(room) -room = ["You are in the hallway between the diner and the balcony. There is a passage way to the north and south",5,None,1,None] - -room_list.append(room) current_room = 0 @@ -56,8 +50,10 @@ while not done: print() print(room_list[current_room][0]) - user_direction = print(input("What direction would you like to go? ")) + user_direction = input("What direction would you like to go? ") print() + next_room = room_list[current_room][1] if user_direction == "n": - print("hi") + print(next_room) + \ No newline at end of file From 33a50f83b19f9bffa79e2b4e824a89faab7f24eb Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 28 Nov 2017 12:47:14 -0600 Subject: [PATCH 31/33] Can get to the diner now --- Lab 07 - Adventure/main_program.py | 38 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 2853fcd..ff2e362 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -3,36 +3,39 @@ # Brady Ballmann # 11/20/2017 + +'''First draft of a Program to navigate through a dungeon''' +# Template of the room: [Room desc. , N, E, S, W] room_list = [] # 0 -room = ["You are in a entrance room. There is a passage to the north",1,None,None,None] +room = ["You are in an entrance room.",1,None,None,None] room_list.append(room) # 1 -room = ["You are in the Diner. There is a passage way to the east, and south",None,2,0,None] +room = ["You are in the Diner. ",None,2,0,None] room_list.append(room) # 3 -room = ["You are in the bedroom hallway. There is a passage way to the East and West",None,3,None,1] +room = ["You are in the bedroom hallway.",None,3,None,1] room_list.append(room) # 4 -room = ["You are in the bedroom. There is a passage way to the North and West",8,None,None,2] +room = ["You are in the bedroom. ",8,None,None,2] room_list.append(room) # 5 -room = ["You are in the hallway between the bathroom and the bedroom. There is a passage way to the north and south",3,None,7,None] +room = ["You are in the hallway between the bathroom and the bedroom. ",3,None,7,None] room_list.append(room) # 6 -room = ["You are in the Bathroom. There is a passage way to the South and West",None,None,8,6] +room = ["You are in the Bathroom.",None,None,8,6] room_list.append(room) # 7 -room = ["You are in the hallway between the balcony and the bathroom. There is a passage way to the East and West",None,7,None,5] +room = ["You are in the hallway between the balcony and the bathroom.",None,7,None,5] room_list.append(room) # 8 @@ -47,13 +50,26 @@ done = False -while not done: +while done == False: print() print(room_list[current_room][0]) user_direction = input("What direction would you like to go? ") print() - next_room = room_list[current_room][1] - if user_direction == "n": - print(next_room) + if user_direction == "n" or "north": + next_room = room_list[current_room][1] + if next_room == None: + print("You can't go that way") + else: + current_room = next_room + elif user_direction == "e": + next_room = room_list[current_room][2] + if next_room == None: + print("You can't go that way") + else: + current_room = next_room + + + + \ No newline at end of file From c66dd7352423a271bfea2e1341ebb72c99ea508a Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Tue, 28 Nov 2017 13:03:50 -0600 Subject: [PATCH 32/33] Can get to the diner now --- Lab 07 - Adventure/main_program.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index ff2e362..86e28c6 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -61,15 +61,9 @@ print("You can't go that way") else: current_room = next_room - elif user_direction == "e": - next_room = room_list[current_room][2] - if next_room == None: - print("You can't go that way") - else: - current_room = next_room - - - - - - \ No newline at end of file + elif user_direction == "e": + next_room = room_list[current_room][2] + if next_room == None: + print("You can't go that way") + else: + current_room = next_room \ No newline at end of file From d8034c12805e97860e78ccb18178a07e69e4c5dd Mon Sep 17 00:00:00 2001 From: BradyBallmann Date: Wed, 29 Nov 2017 12:40:45 -0600 Subject: [PATCH 33/33] Finished program added East, South, and West --- Lab 07 - Adventure/main_program.py | 73 ++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 86e28c6..6740997 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -18,52 +18,79 @@ room_list.append(room) -# 3 +# 2 room = ["You are in the bedroom hallway.",None,3,None,1] room_list.append(room) -# 4 -room = ["You are in the bedroom. ",8,None,None,2] - -room_list.append(room) -# 5 -room = ["You are in the hallway between the bathroom and the bedroom. ",3,None,7,None] - -room_list.append(room) -# 6 -room = ["You are in the Bathroom.",None,None,8,6] +# 3 +room = ["You are in the bedroom. ",4,None,None,2] room_list.append(room) -# 7 -room = ["You are in the hallway between the balcony and the bathroom.",None,7,None,5] +# 4 +room = ["You are in the hallway between the bathroom and the bedroom. ",5,None,3,None] room_list.append(room) -# 8 -room = ["You are outside on the balcony. There is a passage way to the East",None,None,4,None] +# 5 +room = ["You are in the Bathroom.",None,None,4,None] room_list.append(room) current_room = 0 - - done = False -while done == False: +while not done: print() - print(room_list[current_room][0]) + print(room_list[current_room][0]) + + if room_list[current_room][1] != None: + print("There is an exit to the North") + if room_list[current_room][2] != None: + print("There is an exit to the East") + if room_list[current_room][3] != None: + print("There is an exit to the South") + if room_list[current_room][4] != None: + print("There is an exit to the West") + user_direction = input("What direction would you like to go? ") print() - if user_direction == "n" or "north": + # Printing the exits + + + if user_direction == "n" or user_direction == "north": next_room = room_list[current_room][1] if next_room == None: print("You can't go that way") else: - current_room = next_room - elif user_direction == "e": + current_room = next_room + + + elif user_direction == "e" or user_direction == "east": next_room = room_list[current_room][2] 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 + + elif user_direction == "s" or user_direction == "south": + next_room = room_list[current_room][3] + if next_room == None: + print("You can't go that way") + else: + current_room = next_room + + elif user_direction == "w" or user_direction == "west": + next_room = room_list[current_room][4] + if next_room == None: + print("You can't go that way") + else: + current_room = next_room + + else: + print("The program does not understand what you typed") + + + + + \ No newline at end of file