From b57c8049cfa99d5840ae3f934997f0f49d0a2295 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 1 Nov 2017 09:10:06 -0500 Subject: [PATCH 01/18] completed chapter 1 --- Lab 01 - Calculator/lab_01_part_a.py | 9 ++++++++- Lab 01 - Calculator/lab_01_part_b.py | 12 +++++++++++- Lab 01 - Calculator/lab_01_part_c.py | 9 ++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..aef9161 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,8 @@ -# +#!/usr/bin/env python3 +#Fahrenheit to Celsius conversion +#Ryan Rosvall +#11/1/17 + +temperature = int(input("Enter temperature in Fahrenheit: ")) +conversion = ((temperature - int(32)) * 5/9) +print('The temperature in Celsius: ' + str(conversion)) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..21ad599 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,11 @@ -# +#!/usr/bin/env python3 +#Trapezoid Area Calculator +#Ryan Rosvall +#11/1/17 + +print('Area of a trapezoid') +height = int(input('Enter the height of the trapezoid: ')) +lengthBottom = int(input('Enter the length of the bottom base')) +lengthTop = int(input('Enter the length of the top base: ')) +calculation = (1/2) * (lengthBottom + lengthTop) * height +print('The area is: ' + str(calculation)) diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..c0acaca 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,8 @@ -# +#!/usr/bin/env python3 +#Circle Area Calculator +#Ryan Rosvall +#11/1/17 + +number = int(input('Enter the radius: ')) +calculation = (3.14) * number ** 2 +print('Area of circle: ' + str(calculation)) From b5832665e33b3b6499e36eab00544103ed9902a8 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Thu, 2 Nov 2017 07:51:56 -0500 Subject: [PATCH 02/18] Finished lab 3 --- Lab 03 - Create a Quiz/main_program.py | 76 +++++++++++++++++++++++++- 1 file changed, 75 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..5eca9a9 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,75 @@ -# +#!/usr/bin/env python3 +#Quiz +#Ryan Rosvall +#11/1/17 + +print('Quiz time!') +totalRight = 0 +print() +questionOne = input('The beaver is the national emblem of which country? ') +if questionOne == 'Canada' or questionOne == 'canada' or questionOne == 'CANADA': + print() + print('Correct!') + print("You've gained a point! Great job!") + print() + totalRight = totalRight + 1 +else: + print() + print('WRONG!, The correct answer is Canada.') + print() + +questionTwo = input('Who is the director of the Lord of The Rings trilogy? ') +if questionTwo == 'Peter Jackson' or questionTwo == 'peter jackson' or questionTwo == 'PETER JACKSON': + print() + print('Good Job!') + print('Thats another point to your total!') + totalRight = totalRight + 1 +else: + print() + print('WRONG! The correct answer is Peter Jackson') + +print() +print('Next Question!') + +questionThree = input('What is 9 * 9? ') +if questionThree == str(81): + print() + print('Good Job!') + totalRight = totalRight + 1 + if totalRight == 3: + print("YOU'RE ON FIRE!!!") +else: + print() + print('WRONG! The correct answer is 81') + +print() +print('How many cities are in Missouri? ') +a = print('a = 108') +b = print('b = 121') +c = print('c = 105') +d = print('d = 117') +print() +questionFour = input('Choose your answer: ') +if questionFour == "c": + print() + print('Outstanding!') + totalRight = totalRight + 1 +else: + print() + print('WRONG! The correct answer is c.') + +print() +print('Next Question!') +questionFive = input('Al Capone was sentenced to 11 years in prison for what crime? ') +if questionFive == 'Tax Evasion' or questionFive == 'tax evasion' or questionFive == 'TAX EVASION': + print() + print('Good Job!') + totalRight = totalRight + 1 +else: + print() + print('WRONG! The correct answer is Tax Evasion') + +print() +print('The amount you got right was: ' + str(totalRight) + '/5') +print() +print('Your % was ' + str((totalRight/5) * 100)) From 2e42cc818f16060e73ef5d458b2e165bd3a9d8f6 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Thu, 2 Nov 2017 08:53:15 -0500 Subject: [PATCH 03/18] completed worksheet 1 --- Lab 03 - Create a Quiz/main_program.py | 1 + Worksheets/worksheet_01.txt | 49 +++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 5eca9a9..ba8db59 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -38,6 +38,7 @@ totalRight = totalRight + 1 if totalRight == 3: print("YOU'RE ON FIRE!!!") + else: print() print('WRONG! The correct answer is 81') diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..e3be53a 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -7,22 +7,33 @@ 1. Write a line of code that will print your name. + print("RyanRosvall") + 2. How do you enter a comment in a program? + use the # and type behind it. + EX: #Ryan + 3. What do the following lines of code output? ALSO: Why do they give a different answer? print(2 / 3) print(2 // 3) + the first one divides 2 by 3 and the 2nd one does the same thing but rounds the number. + 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) + The variables arent the same. + 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -33,7 +44,9 @@ area area_of_rectangle Area_Of_Rectangle - + + area_of_rectangle is because its descriptive and you'll know what it is when you see it in the code. + 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.) @@ -61,15 +74,21 @@ total% #left + account#, great.big.variable, total%, #left + 8. Why does this code not work? print(a) a = 45 + You need to set what the variable is = to before you print it. + 9. Explain the mistake in this code: pi = float(3.14) + it needs to be == instead of = + 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -79,6 +98,8 @@ area = pi * radius ** 2 print(area) + You can just make pi = 3.14 from the start. + 11. Explain the mistake in the following code: x = 4 @@ -86,6 +107,8 @@ a = ((x) * (y)) print(a) + the program will work but the variables need to be named better. + 12. Explain the mistake in the following code: x = 4 @@ -93,23 +116,37 @@ a = 3(x + y) print(a) + the 'int' object is not callable + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) + you dont need float, you can add that later. + 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 ) + the top one is better because it is compact and faster to run. + 15. What is a constant? + Something that always stays the same. + 16. How are variable names for constants different than other variable names? + A constant is something that is static so the variable name would be different by default. + 17. What is a single quote and what is a double quote? Give and label an example of both. + ' single quote, EX: 'ryan' + " double quote, EX: "ryan" + They do the same thing in python, there is no difference. + 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.) @@ -117,29 +154,39 @@ 19. Can a Python program print text to the screen using single quotes instead of double quotes? + Yes, they do the same thing. + 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) + It will divide first because of order of operations. + You'll need to add more brackets to make it work. 21. What is an ``operator'' in Python? + Symbols in python that carry out a problem. + + or - to do addition or subtraction. + 22. What does the following program print out? x = 3 x + 1 print(x) + It prints x becasue x = 3, if you want to add 1 you do x = x + 1 23. Correct the following code: user_name = input("Enter your name: )" + user_name = input("Enter your name: ") 24. Correct the following code: value = int(input(print("Enter your age"))) + value = int(input('Enter your age: ')) From 11b6c8132fa5791e2f4c70fe70cdeddfd45e94e5 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Fri, 3 Nov 2017 08:31:48 -0500 Subject: [PATCH 04/18] Finished lab 4 --- Lab 04 - Camel/main_program.py | 91 +++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..72f0792 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,90 @@ -# +#!/usr/bin/env python3 +#Camel Program +#Ryan Rosvall +#11/2/17 + +import random + +milesTraveled = 0 +thirst = 0 +camelTiredness = 0 +nativeDistance = -20 +canteenDrinks = 3 + + + +print("Welcome to Camel!") +print("You have stolen a camel to make your way across the great Mobi desert.") +print("The naties want their camel back and are chasing you down! Survive your dsesert trek and out rin the natives.") +print() +done = False +while done == False: + 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.") + choice = input("Your choice? ").upper() + print() + if thirst >= 6: + if choice != "A": + print("You died of thirst!") + done = True + elif thirst > 4: + if choice != "A": + print("You are thirsty.") + if camelTiredness > 8: + if choice != "D": + print("Your camel is dead.") + done = True + elif camelTiredness > 5: + if choice != "D": + print("Your camel is getting tired.") + if nativeDistance > milesTraveled: + print("The natives caught you.") + done = True + if nativeDistance < 15: + print("The natives are getting close.") + if milesTraveled == 200: + print("You won!") + done = True + if choice == "Q": + done = True + elif choice == "E": + print("Miles traveled: " + str(milesTraveled)) + print("Drinks in canteen: " + str(canteenDrinks)) + print("The natives are " + str(milesTraveled - nativeDistance) + " miles behind you.") + print() + elif choice == "D": + camelTiredness = 0 + print("Your camel is happy :)") + print() + elif choice == "C": + m = random.randint(10, 20) + milesTraveled = milesTraveled + m + print("You traveled " + str(m) + ' miles') + camelTiredness = camelTiredness + random.randint(1, 3) + thirst = thirst + 1 + n = random.randint(7, 14) + nativeDistance = nativeDistance + n + print('The natives moved ' + str(n) + ' miles') + print() + elif choice == "B": + m = random.randint(5, 12) + milesTraveled = milesTraveled + m + print("You traveled " + str(m) + " miles.") + thirst = thirst + 1 + camelTiredness = camelTiredness + 1 + n = random.randint(5, 8) + nativeDistance = nativeDistance + n + print('The natives moved ' + str(n) + ' miles') + + print() + elif choice == "A": + if canteenDrinks > 0: + canteenDrinks = canteenDrinks - 1 + thirst = 0 + else: + print("You cannot drink from your canteen because it is empty.") + From 5dd7e05e1c065a07c380d498fc99f5a4ab2e6168 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Fri, 3 Nov 2017 10:07:41 -0500 Subject: [PATCH 05/18] Finished Lab 5 --- Lab 05 - Create a Picture/main_program.py | 62 ++++++++++++++++++++++- 1 file changed, 61 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..dca6df6 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,61 @@ -# +#!/usr/bin/env python3 +#Picture game +#Ryan Rosvall +#11/3/17 + +import pygame + +pygame.init() + +black = (0, 0, 0) +white = (255, 255, 255) +green = (0, 255, 0) +red = (255, 0, 0) + +size=[700,500] +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("Ryan's Super Cool Drawing Game") + +done = False + +clock = pygame.time.Clock() + +while done == False: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + + screen.fill(white) + + pygame.draw.rect(screen, black, [150, 150, 350, 300]) + + #for x in range(0, 100, 20): + for x in range(150, 350, 50): + pygame.draw.line(screen, black, [150, 150], [350, 100], 5) + pygame.draw.line(screen, black, [150, 158], [350, 108], 2) + pygame.draw.line(screen, black, [150, 166], [350, 116], 2) + pygame.draw.line(screen, black, [150, 174], [350, 124], 2) + pygame.draw.line(screen, black, [350, 150], [350, 100], 5) #downline + + font = pygame.font.Font(None, 20) + + text = font.render('Pg.9', True, black) + screen.blit(text, [315,135] ) + + + pygame.draw.ellipse(screen, green, [350, 350, 40, 40]) + pygame.draw.ellipse(screen, green, [250, 350, 40, 40]) + pygame.draw.rect(screen, white, [250, 250, 140, 100]) + pygame.draw.rect(screen, white, [380, 300, 50, 50]) + + #pygame.draw.rect(screen, black, [50, 50, 250, 100] + + pygame.display.flip() + + + clock.tick(20) + +pygame.quit() + From 8cb0b28ae2e015213543cb55683b7d48cedd830f Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Mon, 6 Nov 2017 07:55:16 -0600 Subject: [PATCH 06/18] Finished worksheet 2. --- Worksheets/worksheet_02.txt | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..6ac619c 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -7,36 +7,89 @@ binary, decimal, and hexadecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.) + 67 = 01000011 + 2. Give an example of a decimal number. + 67 + 3. Give an example of a hexadecimal number. + 67 = 43 + 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 program that processes statements written in a particular code that a computer can read. + 6. What is source code? + The original code. + 7. What is machine language? (Don't just say binary. That's not correct.) + A language like binary or hexidecimal that a computer can read and respond to. + 8. What is a first generation language? (Don't just say binary. That's not correct.) + A machine-level programming language. + 9. What is a second generation language? + A gererational way to categorize assembly languages. + 10. What is a third generation language? (Explain, don't just give one example.) + A generational way to categorize high-level computer programming languages like C++ or Java. + 11. What is an interpreter and how does it differ from a compiler? + An interpreter translates programs one statement at a time while a compiler scans the entire program and translates it as a whole. + 12. Search the web and find some of the most popular programming languages. List the website(s) you got the information from and what the languages are. + https://www.inc.com/larry-kim/10-most-popular-programming-languages-today.html + + Java + Python + C + Ruby + JavaScript + C# + PHP + Objective-C + SQL + C + 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. + https://www.indeed.com/q-Programmer-jobs.html + C# + Java + C++ + 14. What is the difference between the ``syntax'' and ``semantics'' of a language? + Syntax: formal rules governing the construction of valid statements in a language. + Semantics: set of rules which ive the meaning of a statement. + 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - + + Asus Zenfone Max 3: + CPU: Quad-core 1.25 GHz Cortex-A53 + GPU: Mali-T720MP2 + RAM: 3GB + - Has a fingerprint scanner. + The phone is great and ive never had any problems with it, quality. From 156aacceead0457fd15677673a0b1d939372ecff Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Mon, 6 Nov 2017 08:21:52 -0600 Subject: [PATCH 07/18] Completed worksheet 3. --- Worksheets/worksheet_03.txt | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..9f85973 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,14 +10,30 @@ print("It is hot outside.") else: print("It is not hot out.") + + Missing an int in front 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 your number: ")) + if number > 0: + print("Your number is positive.") + elif number < 0: + print("Your number negative.") + else: + print("I dont like your number >:(, It 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 your number")) + if number > -10: + print("Success") + elif number < 10: + print("FAILURE!!") + 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -28,6 +44,8 @@ else: print("Incorrect.") + He should set the A and B print statements to a variable. + 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. @@ -39,6 +57,9 @@ else: print("x is not positive.") + Issue 1 is that x == 4 needs to be removed or replaced with 0 instead of 4. + Issue 2 is that he should use an elif + 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") @@ -53,12 +74,19 @@ else print("Incorrect! It is Beaker.") + 1 = else is indented wrong. + 2 = needs to be if a == "Beaker": + 3 = adding on to the last one it needs to be if a == "Beaker".title + 4 = the first line is wrongly indented + 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!") + needs an else statement to provide an answer if its not one of those two. + 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. @@ -79,6 +107,14 @@ if z: print("Buzz") + it will print: + x = 5 + y = False + z = True + Fizz + + I was wrong, Fizz is replaced with buzz on print. + 10. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts) @@ -97,6 +133,32 @@ print(x == 5 and y == 5) print(x == 5 or y == 5) + My Guess: + True + False + True + False + False + True + True + False + True + False + False + + Actual output: + 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) @@ -110,6 +172,29 @@ print( (2 == 2) == True ) print(3 < "3") + My guess: + True + False + True + True + True + True + False + True + Last one will print an error because ones an int and ones a string. + + Actual 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 @@ -130,6 +215,9 @@ else if user_input = C: money = 50 + After they ask for the input, the selected option needs to be: + money = money + 50 or what number is needed. + There also needs to be a space after the ? so the texts arent side to side. From b9bbcaa1eaa447b62ef5c9b30e9c8f7d53639f03 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 8 Nov 2017 10:06:54 -0600 Subject: [PATCH 08/18] Completed worksheet 4 --- Worksheets/worksheet_04.txt | 101 +++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..3335d8e 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -14,17 +14,33 @@ 1. Write a Python program that will use a for loop to print your name 10 times, and then the word ``Done'' at the end. + 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 Gold") + 3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive. + print(*range(2, 101, 2)) + 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. + n = 10 + while n >= 0: + print(n) + n = n - 1 + print("Blast off!") + 5. There are three things wrong with this program. List each. (3 pts) print("This program takes three numbers and returns the sum.") @@ -34,13 +50,23 @@ x = input("Enter a number: ") total = total + i print("The total is:", x) - + + 1 = there needs to be a space after the : in print. + 2 = the input needs to be before the for loop. + 3 = needs to ask for 3 different inputs so you can do it with different numbers. + 6. Write a program that prints a random integer from 1 to 10 (inclusive). + from random import randint + print(randint(1, 10)) + 7. Write a program that prints a random floating point number somewhere between 1 and 10 (inclusive). Do not make the mistake of generating a random number from 0 to 10 instead of 1 to 10. + from random import randint + print(float(randint(1, 10))) + 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -49,6 +75,31 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. +zero = 0 +positive = 0 +negative = 0 + +a = int(input("Enter your 1st number: ")) +b = int(input("Enter your 2nd number: ")) +c = int(input("Enter your 3rd number: ")) +d = int(input("Enter your 4th number: ")) +e = int(input("Enter your 5th number: ")) +f = int(input("Enter your 6th number: ")) +g = int(input("Enter your 7th number: ")) +sum = ([a + b + c + d + e + f + g]) +print(sum) +if a or b or c or d or e or f or g > 0: + positive = positive + 1 +elif a or b or c or d or e or f or g < 0: + negative = negative + 1 +else: + zero = zero + 1 +print("There was " + str(zero) + " zeros.") +print("There were " + str(positive) + " positive numbers.") +print("There were " + str(negative) + " negative numbers.") + + + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +108,24 @@ * 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. +heads = 0 +tails = 0 +count = 0 + +from random import randint +while count < 50: + number = randint(0, 1) + if number == 1: + print("Heads!") + heads = heads + 1 + if number == 0: + print("Tails!") + tails = tails + 1 + count = count + 1 +print("Amount of Heads: " + str(heads)) +print("Amount of Tails: " + str(tails)) + + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -66,4 +135,32 @@ * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. - +import sys +choice = input("Rock Paper or Scissors? ") +from random import randint +number = randint(1, 3) +if number == 1: + print("Rock!") +if number == 2: + print("Paper!") +if number == 3: + print("Scissors!") +if choice == "Scissors": + choicenum = 3 +if choice == "Paper": + choicenum = 2 +if choice == "Rock": + choicenum = 1 +if choicenum == number: + print("You tied.") + sys.exit(0) +if choicenum == 2 and number == 1: + print("You won!") +elif choicenum == 1 and number == 3: + print("You won!") +elif choicenum == 3 and number == 2: + print("You won!") +else: + print("You lost.") + + From 332c396d7059de3a5c67f1abf63726ce2af77fb6 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Thu, 9 Nov 2017 08:08:25 -0600 Subject: [PATCH 09/18] Completed Worksheet 5 --- Worksheets/worksheet_05.txt | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..ddf4c19 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -8,21 +8,36 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + cartesian coordinate system starts (0, 0) in the middle while computer coordinate system starts (0, 0) at the top left. + 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 + import sys + 3. Explain how WHITE = (255, 255, 255) represents a color. + it displays all the colors which makes white, if it were (0, 0, 0) it would be black becuase its not reflecting any color. + 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.) + constants will be in all uppercase and ones that will change will be in all lower. + 5. What does the pygame.display.set_mode() function do? + displays a new window where you can have a visual output. + 6. What does this for event in pygame.event.get() loop do? + for every event in the returned list, copy the event to the variable. + 7. What is pygame.time.Clock used for? + the amount of frames per second + 8. For this line of code: (3 pts) pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5) @@ -32,11 +47,19 @@ * What does [100, 100] do? * What does 5 do? + 1 = displays a screen that you can do visual stuff on. + 2 = where the line begins + 3 = where the line ends + 4 = how thick the line will be. 9. What is the best way to repeat something over and over in a drawing? + edit the variable to make it how many times you want it. + 10. When drawing a rectangle, what happens if the specified line width is zero? + the rectangle will be filled. + 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? @@ -45,25 +68,44 @@ pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) + 1 = teh x, y origin is the start point, 20 20. + 2 = the origin isnt the center of the circle, its the top left corner. + 3 = the length and width is just like a rectangle. + 12. When drawing an arc, what additional information is needed over drawing an ellipse? + start angle and stop angle + 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + pygame.font + font.render + screen.blit(text) + 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 it can display the text correctly, if its not there it wont display. + 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) + [50,100],[0,200],[200,200],[100,50] + 16. What does pygame.display.flip() do? + makes all of the text, lines, etc display on the screen. + 17. What does pygame.quit() do? + makes you able to close the window that opens. + 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. + draw.circle(screen, green, (150, 120), 60) From 59161455be9c4d01be6346945a4688deace9ff78 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Thu, 9 Nov 2017 09:04:09 -0600 Subject: [PATCH 10/18] Completed chapter 2 --- .../Chapter 2 report on video.docx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lab 02 - Computer History/Chapter 2 report on video.docx b/Lab 02 - Computer History/Chapter 2 report on video.docx index c4ed613..6f74a37 100644 --- a/Lab 02 - Computer History/Chapter 2 report on video.docx +++ b/Lab 02 - Computer History/Chapter 2 report on video.docx @@ -1 +1,12 @@ -Report goes here +Ryan Rosvall +11/9/17 + +Lab 2: Computer History + + Paul Alan and Bill Gates ran a company called Microsoft. They together invented the personal computer. It all happened by accident because they wanted to impress their friends. They never thought it would have went far, they just wanted to mess around and create something new. This all started in Silicon Valley, created by middle class white kids in their garage. Technology is always getting more and more advanced. The original creators of Apple didn't have a time schedule. They coded when they wanted and they always worked well because they liked each other. At first people didn't really care about computers but there was always that one kid who fell in love with it and got into it. + + Back then the idea of putting text into a computer and having it make an outcome was mind boggling. The first computers were huge because they were filled with vacuum tubes which later got replaced with transistors but they were still too big to make a computer on your desk. Finally there was a final piece made called the CPU which made it work all together in a small form. The people who invented the microprocessor was Intel. They power 85% of the worlds computers. The Altair 8800 was the first personal computer. But people really couldn't get their hands on it. + + Ed Roberts wanted to create his own personal computer that you could buy. This was created far far away from silicon valley, IBM, or Intel out in the desert in Albuquerque New Mexico, in a building that was very runned down. Ed Roberts was running a calculator company named Mitts that was going very bad. Nobody was buying his calculators and he was going bankrupt. He needed 65k dollars just to stay afloat. When he created this machine, people were camping out and waiting for it over night. There was a huge demand for this computer and it saved his company. + + Apple started to have explosive growth. The company had more money than they could spend. The company was extremely young too, most workers being around 20 years old. The apple II set a new standard for personal computers. They needed a killer application, this application was called visical. Dan Brickland created the first electronic spreadsheet. It was able to calculate years ahead depending on your inputs and was way advanced for its time. This was planned to calculate things in your budget and make it easier on you. From fe93a8873bf807287ee56e1791147e664766cd8d Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Tue, 14 Nov 2017 10:09:26 -0600 Subject: [PATCH 11/18] Completed Worksheet 6, 1-5 --- Worksheets/worksheet_06.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..b0b9c1a 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,9 @@ while x < 10: print(x) x = x + 2 + + Guess: print 0,2,4,6,8 all on seperate lines. + Actual: print 0,2,4,6,8 all on seperate lines. 2. What does this program print out? @@ -25,6 +28,9 @@ print(x) x = x * 2 + Guess: print 1,2,4,8,16,32 all on seperate lines. + Actual: print 1,2,4,8,16,32 all on seperate lines. + 3. Why is the and x >= 0 not needed? x = 0 @@ -32,6 +38,8 @@ print(x) x = x + 2 + It never goes down, it only increases. Therefore it will always be true so its not needed. + 4. What does this program print out? (0 pts) Explain. (1 pt) x = 5 @@ -41,13 +49,17 @@ print("Blast off!") x = x - 1 + It doesn't print blast off because of the if x == "1" is a string not an int. It does print a countdown from 5 to 0 however. + 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) x = float(input("Enter a number greater than zero: ")) while x <= 0: - print("Too small. Enter a number greater than zero: ") + x = float(input("Too small. Enter a number greater than zero: ")) + + 6. Fix the following code: From 8eb3ccc73a5812d0130c8f94fcfef0c3aeb7bcb4 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 15 Nov 2017 07:42:50 -0600 Subject: [PATCH 12/18] Completed worksheet 6 --- Worksheets/worksheet_06.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index b0b9c1a..ee42007 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -71,6 +71,15 @@ print("Blast-off") + Fixed Code: + x = 10 + + while x > 0: + x = x - 1 + print(x) + + 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) @@ -78,6 +87,8 @@ for i in range(10): print(i) i += 1 + + i += 1 is not needed because it is after the print statement. 8. Explain why the values printed for x are so different. (2 pts) @@ -97,4 +108,4 @@ x += 1 print(x) - + The indentions are different so it is a nested loop, causing a different outcome. From 7c020e8b64af5a97f672d0d37a87228a52f11a48 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 15 Nov 2017 08:27:27 -0600 Subject: [PATCH 13/18] Completed Lab 6 part 1 --- Lab 06 - Loopy Lab/part_1.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..b31eb6d 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,7 @@ - +num = 10 +for row in range(10): + number = "" + for i in range(row): + number += str(num) + " " + num += 1 + print(number) From 975017ecf7fc991cfea7bcfe5a8b970de3f94d81 Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 15 Nov 2017 09:28:31 -0600 Subject: [PATCH 14/18] Completed Lab 6 Part 2 --- Lab 06 - Loopy Lab/part_2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..977a010 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,11 @@ -# +n = int(input("Enter your number of o's: ")) + +for row in range(n * 2): + print("o", end = '') +print() + +for rowLeft in range(n-1): + print("o" + " " * ((n*2) -2) + "o") + +for rowBottom in range(n * 2): + print("o", end = '') From c8f0ac969fb6c199fd5af5c3b43c778ad049a7af Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Thu, 16 Nov 2017 08:11:25 -0600 Subject: [PATCH 15/18] Completed chapter 6 --- Lab 06 - Loopy Lab/part_4.py | 67 +++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..0ccdf5f 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,66 @@ -# +""" + 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 = (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() +_draw = False +# -------- Main Program Loop ----------- +while not done: + # --- Main event loop + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + # --- Game logic should go here + + # --- Screen-clearing code goes here + + # Here, we clear the screen to white. Don't put other drawing commands + # above this, or they will be erased with this command. + + # If you want a background image, replace this clear with blit'ing the + # background image. + screen.fill(BLACK) + + # --- Drawing code should go here + + while not _draw: + for y in range(0, 500, 10): + for x in range(0, 700, 10): + pygame.draw.rect(screen, GREEN, [x, y, 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) + _draw = True + +# Close the window and quit. +pygame.quit() From 65771c119651f4dbfff6dcb8ac6c973f8297f8ca Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Mon, 20 Nov 2017 08:43:15 -0600 Subject: [PATCH 16/18] Completed Worksheet 7 --- Worksheets/worksheet_07.txt | 63 +++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/Worksheets/worksheet_07.txt b/Worksheets/worksheet_07.txt index a87ff3f..af6dadd 100644 --- a/Worksheets/worksheet_07.txt +++ b/Worksheets/worksheet_07.txt @@ -9,6 +9,11 @@ 1. List the four types of data we've covered, and give an example of each: + String - a string of characters + Integer - a numerical value + Floating point - Represent real numbers. + Boolean - True and False + 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,12 +24,18 @@ print(my_list[4]) print(my_list[5]) + 2 + 101 + then gives an error because it starts at 0, so there is no 5 + 3. What does this code print out? my_list=[5, 2, 6, 8, 101] for my_item in my_list: print(my_item) + prints all of the items in the list + 4. What does this code print out? my_list1 = [5, 2, 6, 8, 101] @@ -34,6 +45,9 @@ my_list2[2] = 10 print(my_list2) + [5, 2, 6, 8, 101] + Gives an error on the second print because it is a tuple. + 5. What does this code print out? my_list = [3 * 5] @@ -41,6 +55,9 @@ 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 +65,8 @@ my_list.append(i) print(my_list) + [5, 0, 1, 2, 3, 4] + 7. What does this code print out? print(len("Hi")) @@ -56,18 +75,36 @@ print(len("2")) print(len(2)) + 2 + 9 + 8 + 1 + error, 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" @@ -75,17 +112,24 @@ word += "College" print(word) + 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" @@ -93,10 +137,20 @@ 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. - + + numberList = [] + for i in range(5): + numberInput = input("Enter some numbers: ") + numberList.append(int(numberInput)) + print(numberList) + 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. @@ -105,4 +159,9 @@ my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] - + average = 0 + sums = 0 + myList = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] + sums = sum(myList) + average = sums / len(myList) + print(average) From a90ae962fdecfac911612af35672c21ced5aa15f Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 29 Nov 2017 08:04:55 -0600 Subject: [PATCH 17/18] Completed Chapter 7 --- Lab 07 - Adventure/main_program.py | 67 +++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..c88bfec 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,66 @@ -# +#!/usr/bin/env python3 +#Adventure Game +#Ryan Rosvall +#11/28/17 + +''' first draft of a text adventure game ''' + +#room template: [description, N, E, S, W] + + +current_room = 0 +next_room = 0 + +done = False + +room_list = [] +room = ['You are in the Main Room. ', 1, 5, 3, 2] +room_list.append(room) +room = ['You are in the Window Room, overlooking the extravagant garden. ', None, None, 0, 2] +room_list.append(room) +room = ['You are in the Bedroom.', 1, 0, 7, None] +room_list.append(room) +room = ['You are in the storage room, filled with surgical supplies.', 0, 5, 4, None] +room_list.append(room) +room = ['You have found the hidden storage room! Nothing is here...', 3, None, None, None] +room_list.append(room) +room = ['You are in the lab, there is a dead man strapped to the table.', 6, None, 3, 0] +room_list.append(room) +room = ['You have found an empty room... bummer. Go back to see the dead man now.', None, None, 5, None] +room_list.append(room) +room = ['You Escaped the mansion! Great job!'] +room_list.append(room) + +while done == False: + print(room_list[current_room][0]) + print() + nextMove = input("Which way would you like to go? ") + if nextMove.lower()[0] == "n": + next_room = (room_list[current_room][1]) + current_room = next_room + elif nextMove.lower()[0] == "e": + next_room = (room_list[current_room][2]) + current_room = next_room + elif nextMove.lower()[0] == "s": + next_room = (room_list[current_room][3]) + current_room = next_room + elif nextMove.lower()[0] == "w": + next_room = (room_list[current_room][4]) + current_room = next_room + elif nextMove.lower()[0] == "q": + break + if room_list[current_room][1] != None: + print("\tThere is an exit to the North.") + if room_list[current_room][2] != None: + print("\tThere is an exit to the East.") + if room_list[current_room][3] != None: + print("\tThere is an exit to the South.") + if room_list[current_room][4] != None: + print("\tThere is an exit to the West.") + + if next_room == None: + print("You can't go that way.") + print() + else: + current_room = next_room + continue From f908094030198ac5153fad9adc9e8ed0a47602db Mon Sep 17 00:00:00 2001 From: RyanRosvall Date: Wed, 29 Nov 2017 08:37:08 -0600 Subject: [PATCH 18/18] Completed Chapter 7. --- Lab 07 - Adventure/main_program.py | 35 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index c88bfec..9f9e48b 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -18,7 +18,7 @@ room_list.append(room) room = ['You are in the Window Room, overlooking the extravagant garden. ', None, None, 0, 2] room_list.append(room) -room = ['You are in the Bedroom.', 1, 0, 7, None] +room = ['You are in the Bedroom.', 1, 0, None, None] room_list.append(room) room = ['You are in the storage room, filled with surgical supplies.', 0, 5, 4, None] room_list.append(room) @@ -28,27 +28,11 @@ room_list.append(room) room = ['You have found an empty room... bummer. Go back to see the dead man now.', None, None, 5, None] room_list.append(room) -room = ['You Escaped the mansion! Great job!'] -room_list.append(room) while done == False: + print(room_list[current_room][0]) print() - nextMove = input("Which way would you like to go? ") - if nextMove.lower()[0] == "n": - next_room = (room_list[current_room][1]) - current_room = next_room - elif nextMove.lower()[0] == "e": - next_room = (room_list[current_room][2]) - current_room = next_room - elif nextMove.lower()[0] == "s": - next_room = (room_list[current_room][3]) - current_room = next_room - elif nextMove.lower()[0] == "w": - next_room = (room_list[current_room][4]) - current_room = next_room - elif nextMove.lower()[0] == "q": - break if room_list[current_room][1] != None: print("\tThere is an exit to the North.") if room_list[current_room][2] != None: @@ -57,10 +41,23 @@ print("\tThere is an exit to the South.") if room_list[current_room][4] != None: print("\tThere is an exit to the West.") + next_move = input("Which way would you like to go? ") + if next_move.lower()[0] == "n": + next_room = (room_list[current_room][1]) + elif next_move.lower()[0] == "e": + next_room = (room_list[current_room][2]) + elif next_move.lower()[0] == "s": + next_room = (room_list[current_room][3]) + elif next_move.lower()[0] == "w": + next_room = (room_list[current_room][4]) + elif next_move.lower()[0] == "q": + break if next_room == None: print("You can't go that way.") print() else: current_room = next_room - continue + + +