diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..d790fbf 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,7 @@ -# +#!/usr/bin/env python3 +#Converting Fahrenhiet to Celsius +#Evan Witterholt +#11/2/2017 +temperature = int(input("Enter temperature in Fahrenheit: ")) +convert1 = temperature - 32 +print(fahrenheit * .5556) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..c42c06d 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,10 @@ -# +#!/usr/bin/env python3 +# Finding the area of a trapezoid +# Evan Witterholt +#11/2/2017 +height = int(input("Enter the height of the trapezoid: ")) +length = int(input("Enter the length of the bottom base: ")) +length2= int(input("Enter the length of the top base : ")) +part1 = length + length2 +part2 = height * part1 * 0.5 +print(part2) diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..64fde73 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,9 @@ -# +#!/usr/bin/env python3 +#Finding the area of a circle +#Evan Witterholt +#11/2/2017 +radius = int(input("Enter Radius of the Circle: ")) +pi = 3.14 +part1 = radius**2 +part2 = pi * part1 +print(part2) 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..67e98c5 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,9 @@ Report goes here +Evan Witterholt +12/7/17 + + The computer industry has changed a lot since the creation of this video and the creation of the GUI. Everything used to be + completly text based, but now things are even easier than when the GUI was created. Many things have changed since Windows 95. + We have quicker and easier method to access or save files,transfer documents, and to do just about anything else on our computers. + This video showed that no matter what technology you have, people will always try to innovate and upgrade what they are given. + diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..6f375b1 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,33 @@ -# +#!/usr/bin/env python3 +#Create a Quiz +#Evan Witterholt +#11/6/17 + +score = 0 + +question1 = int(input('How many states are in the US?: ')) +if question1 == 50: + score += 1 +print('That is correct!') + +question2 = int(input('Pluto is a planet. 1 for True or 2 for False?: ')) +if question2 == 2: + score += 1 +print('That is correct!') + +question3 = int(input('What is 9+10?: ')) +if question3 == 19: + score += 1 +print('That is correct!') + +question4 = int(input('How many planets are between the Earth and the Moon?: ')) +if question4 == 0: + score += 1 +print('That is correct!') + +question5 = int(input('What question are you on?: ')) +if question5 == 5: + score += 1 +print('That is correct!') + +print (score, 'out of 5') diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..4673e9b 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,97 @@ -# +#!/usr/bin/env python3 +# Camel Game +# Evan Witterholt +# 11/11/17 + + +import random + +miles = 0 +hunger = 0 +cowboys = -20 +thirst = 0 +horsetiredness = 0 + +print('Welcome to Stealy Horsey!') +print('You have stolen the Krabby Patty Secret Formula and kidnapped a horse to make your way across the Wild West.') +print('The cowboys want their horse back and are chasing you down! Survive your') +print('western trek and outrun the cowboys.') + + +done = False +while done == False: + + + townlocation = random.randint(1,21) + cowboyslocation = random.randint(7,15) + milesgone = random.randint(10,21) + milesbehind = miles - cowboys + + + + print('A. Drink from canteen.') + print('B. Continue at moderate speed.') + print('C. Continue at full speed.') + print('D. Stop for the night.') + print('E. Status check.') + print('Q. Quit.') + + userchoice = input('Your choice: ') + + if userchoice.upper() == 'Q': + done = True + + elif userchoice.upper() == 'E': + print('\nMiles traveled:' , str(miles),'\nHunger:' ,str(hunger), '\nThirst:' ,(thirst), '\nHorse Tiredness:',str(horsetiredness),'\nMiles Cowboys have traveled:',str(cowboys),'miles.\n') + + elif userchoice.upper() == 'D': + print('\nYou found more food and water.\n''The horse is well rested.' + '\nCowboys are',str(milesbehind), 'miles behind.\n') + cowboys += cowboyslocation + horsetiredness -= horsetiredness + hunger -= hunger + thirst -= thirst + + + + + elif userchoice.upper() == 'C': + miles = miles + random.randint(15, 23) + print('\nYou traveled:',str(milesgone), 'miles\n', '\nCowboys are',str(milesbehind), 'miles behind.\n' ) + hunger += 1 + cowboys += cowboyslocation + horsetiredness += 4 + + elif userchoice.upper() == 'B': + miles = miles + random.randint(5,13) + print('\nYou traveled:', str(milesgone), 'miles\n','Cowboys have traveled', str(cowboyslocation),'miles.\n') + hunger += 1 + cowboys += cowboyslocation + horsetiredness += 2 + + elif userchoice.upper() == 'A': + thirst -=3 + cowboys += cowboyslocation + print('You stopped to drink water.\nThe Cowboys traveled', str(cowboyslocation), 'miles.\n') + + if horsetiredness < 9 and horsetiredness > 6: + print('The horse needs rest now.\n') + + elif horsetiredness > 10: + print('The horse died.') + done = True + + elif miles <= cowboys: + print('You have been killed.') + done = True + + elif miles >= 200: + print('You escaped!') + done = True + + elif hunger <= -5: + print('You starved to death.') + done = True + + elif thirst <= -5: + print('You died of dehydration.') + doen = True diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..5addf37 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,37 @@ -# +#!/usr/bin/env python3 +# Drawing a picture in python +# Evan Witterholt +# 11/11/17 + +import pygame + +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) + +done = False + +clock = pygame.time.Clock() + +while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + screen.fill(GREEN) + + pygame.draw.rect(screen,BLACK,[-25,35,750,150],2) + + pygame.display.flip() + + clock.tick(60) + + +pygame.quit() + + + diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..fc9f37a 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,26 +6,28 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. - + print("Evan Witterholt") 2. How do you enter a comment in a program? - + # 3. What do the following lines of code output? ALSO: Why do they give a different answer? - - print(2 / 3) - print(2 // 3) + / is division, // is floor division + print(2 / 3) = 0.6666666666 + print(2 // 3) = 0 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. + pi = 9 5. Why does this code not work? - + A and a are two different variables A = 22 print(a) 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? - + + area_of_rectangle a A Area @@ -43,7 +45,7 @@ APPLE Apple2 1Apple - account number + account number this one account_number account.number accountNumber @@ -58,20 +60,21 @@ great.big.variable 2x x2x - total% - #left + total% this one + #left this one - 8. Why does this code not work? + 8. Why does this code not work? The print statement needs to be last print(a) a = 45 9. Explain the mistake in this code: - + Only the first 3 digits are printing pi = float(3.14) 10. This program runs, but the code still could be better. Explain what is wrong with the code. + You do not need x =3.14 radius = float(input("Radius:")) x = 3.14 @@ -80,51 +83,62 @@ print(area) 11. Explain the mistake in the following code: - + There are excess parenthesis x = 4 y = 5 a = ((x) * (y)) print(a) 12. Explain the mistake in the following code: - + There is no int. All the numbers are being typed as strings. x = 4 y = 5 a = 3(x + y) print(a) 13. Explain the mistake in the following code: + A radius does not need a float command radius = input(float("Enter the radius:")) 14. Do all these print the same value? Which one is better to use and why? - + Yes, the first one + print(2/3+4) print(2 / 3 + 4) print( 2 / 3+ 4 ) 15. What is a constant? - + A constant is a variable that, if changed, will result in an error. + 16. How are variable names for constants different than other variable names? - + A constant stays the same but a variable will be able to change. + "" "" + 17. What is a single quote and what is a double quote? Give and label an example of both. + 'my name' + "my name" + 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("" ""/n) 19. Can a Python program print text to the screen using single quotes instead - of double quotes? + of double quotes? Yes 20. Why does this code not calculate the average? - + Order of Operations calls for division to be done before addition print(3 + 4 + 5 / 3) 21. What is an ``operator'' in Python? - + Operators carry out arithmetic or logical computation (+, -, >, etc.) + 22. What does the following program print out? + It prints 3. x+1 does not print. x = 3 x + 1 @@ -133,12 +147,20 @@ 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: ")) + + + + + + + + diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..f52c79d 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,54 @@ 1. Give an example of a binary number. (While a number such as ``1'' can be a binary, decimal, and hexadecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.) - + 01101100 + 2. Give an example of a decimal number. - + 74 + + 3. Give an example of a hexadecimal number. - + 3FA + 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. - + 1, 2, 4, 8, 16 + 5. What is a compiler? - + Converts source code to machine code + 6. What is source code? - + Programs written by the developer + 7. What is machine language? (Don't just say binary. That's not correct.) - + The native code ran by the computer + 8. What is a first generation language? (Don't just say binary. That's not correct.) - + Machine language + 9. What is a second generation language? - + Assembly language + 10. What is a third generation language? (Explain, don't just give one example.) - + Python, C. Logical structures. + 11. What is an interpreter and how does it differ from a compiler? - + An interpreter and a compiler are almost the same thing, except the interpreter does not need to convert code to objects to execute them. + 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. - + Java, Python, C, Ruby, Javascript, C#, PHP, Objective-C, SQL. Inc.com + 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. - + Java was the most popular one. Indeed.com + 14. What is the difference between the ``syntax'' and ``semantics'' of a - language? - + language? Syntax are grammatical structures while Semantics are meanings for vocabulary symbols. + + 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - + + Operating system: Dolphin OS + CPU: IBM PowerPC Gekko @ 486 MHz diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..3f28e69 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -4,6 +4,7 @@ 1. What is missing from this code? (1 pt) + A second parenthesis at the end of the input statement temperature = float(input("Temperature: ") if temperature > 90: @@ -14,10 +15,24 @@ 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("That number is positive") + elif number < 0: + print("That number is negative") + elif number == 0: + print("That 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) - + + number = int(input("Enter a number: ")) + if number > -10 and number < 10: + print("Success") + else: + print("Failure") + 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -27,11 +42,13 @@ print("Correct!") else: print("Incorrect.") - - 5. There are two things wrong with this code that tests if x is set to a + The choices do not print until the user inputs an answer + + 5. There are two things wrong with this code that tests if x is set to a positive value. One prevents it from running, and the other is subtle. Make sure the if statement works no matter what x is set to. Identify both issues. (2 pts) + x is not defined and there does not need to be two equal signs in line one. x == 4 if x >= 0: @@ -40,12 +57,14 @@ print("x is not positive.") 6. What three things are wrong with the following code? (3 pts) + There needs to be 2 equal signs in front of the 3 and x is not defined. x = input("Enter a number: ") if x = 3 print("You entered 3") 7. There are four things wrong with this code. Identify all four issues. (4 pts) + There needs to be two = in front of a. The else needs to be alligned with the if. The else needs a : after it. a needs to be answer. answer = input("What is the name of Dr. Bunsen Honeydew's assistant? ") if a = "Beaker": @@ -54,6 +73,7 @@ print("Incorrect! It is Beaker.") 8. This program doesn't work correctly. What is wrong? (1 pt) + The output will always be "That is good to hear!" x = input("How are you today?") if x == "Happy" or "Glad": @@ -67,6 +87,8 @@ While you don't need to write an explanation, make sure you understand why the computer prints what it does. Don't get caught flat-footed when you need to know later. (2 pts) + Guess: I think it will print "Buzz" + Answer: It printed Buzz x = 5 y = x == 6 @@ -81,6 +103,19 @@ 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) + Guess: I think there will be an error + Answer: It printed + True + False + True + False + False + True + False + False + True + False + True x = 5 y = 10 @@ -99,6 +134,8 @@ 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) + Guess:It will print wether each one is true or false + Answer: It printed true and false with an end error print("3" == "3") print(" 3" == "3") @@ -115,6 +152,10 @@ The programmer wants to set the money variable according to the initial occupation the user selects. (1 pt) + The else if statements need to be elifs, the choices are not defined, and the statements need double equal signs. + + + print("Welcome to Oregon Trail!") print("A. Banker") diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..019c731 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -14,17 +14,39 @@ 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 number 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 color in range(20): + print('Red') + print('Gold') + + + 3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive. + for even in range(2, 101, 2): + print(even) + + 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. - + + for number in range(10,-1,-1): + print(number) + 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.") @@ -37,10 +59,22 @@ 6. Write a program that prints a random integer from 1 to 10 (inclusive). + import random + + print (random.randint(1,11)) + + 7. Write a program that prints a random floating point number somewhere between 1 and 10 (inclusive). Do not make the mistake of generating a random number from 0 to 10 instead of 1 to 10. + + import random + print (random.uniform(1.0,10.0)) + + + + 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -49,7 +83,27 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. - 9. Coin flip tosser: (4 pts) + + total = 0 + totalpositive = 0 + totalnegative = 0 + totalzero = 0 + number = input('Enter 7 numbers: ') + number = number.split() + for num in number: + total = total+int(num) + if int(num) > 0: + totalpositive += 1 + elif int(num) < 0: + totalnegative += 1 + else: + totalzero += 1 + print(total) + print(totalpositive, totalnegative, totalzero) + + + + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. * Instead of 0 or 1, print heads or tails. Do this @@ -57,6 +111,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 = 1 + tails = 0 + + for coinflips in range(50): + number = random.randint(0,2) + if number == 1: + heads += 1 + else: + tails += 1 + print('Head:',str(heads),'\nTails:',str(tails)) + + + + + + + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -67,3 +140,56 @@ * Add conditional statement to figure out who wins. + import random + +rock = 1 +paper = 2 +scissors = 3 + +choice = int(input('Choose 1, 2, or 3: ')) + +for selection in range(1): + number = random.randint(0,3) + if number == 1: + print('Rock') + elif number == 2: + print('Paper') + elif number == 3: + print('Scissors') + + if choice == 1: + if number == 2: + print('Loss') + elif number == 3: + print('Win') + elif number == 1: + print('Draw') + + if choice == 2: + if number == 2: + print('Draw') + elif number == 3: + print('Loss') + elif number == 1: + print('Win') + + if choice == 3: + if number == 2: + print('Win') + elif number == 3: + print('Draw') + elif number == 1: + print('Loss') + + + + + + + + + + + + + diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..c1474b0 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -7,63 +7,102 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + + The y coordinates are reversed and objects drawn in negative space will be off screen. 2. Before a Python Pygame program can use any functions like pygame.display.set_mode(), what two lines of code must occur first? + import pygame + pygame.init() + + 3. Explain how WHITE = (255, 255, 255) represents a color. + RGB colors range from 0-255, 0 representing no color and 255 representing full color. 255 in all three ranges mixes all 3 colors to make white. + + 4. When do we use variable names for colors in all upper-case, and when do we use variable names for colors in all lower-case? (This applies to all variables, not just colors.) + Uppercase variables are contants, while lowercase variables cna be changed + 5. What does the pygame.display.set_mode() function do? + It can be used to create a window of a specified size. + 6. What does this for event in pygame.event.get() loop do? + It removes evnt from a queue and puts them inside a list. + 7. What is pygame.time.Clock used for? + It tracks amount of time or manages framerate. + 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? Displays the screen. + * What does [0, 0] do? The starting coordinate of the line. + * What does [100, 100] do? The end coordinate of the line. + * What does 5 do? Line width. - + + + 9. What is the best way to repeat something over and over in a drawing? + + You should use an event loop. 10. When drawing a rectangle, what happens if the specified line width is zero? + The line will not be there. + 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? The upper left of the rectangle boundary. + * What is the length and the width of the ellipse? The Length x Width is 250 x 100. pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) 12. When drawing an arc, what additional information is needed over drawing - an ellipse? + an ellipse? + + Start and end coordinates for the angles. 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + + .Create a variable to hold information about the font being used + .The program needs to create an image of the text + .Tell the program whre to place the image 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. + The line should only run once becasue the font and size do not change. + 15. What are the coordinates of the polygon that the code below draws? + (50,100) (0,200) (200,200) (100,50) + pygame.draw.polygon(screen, BLACK, [[50,100],[0,200],[200,200],[100,50]], 5) 16. What does pygame.display.flip() do? + It flips the display so the image can be shown instead of causing the screen to flicker. + 17. What does pygame.quit() do? + It ends the program. + 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, red,(200, 100), 30) + diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..07e8431 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -13,6 +13,9 @@ 1. What does this program print out? (Remember: TWO answers. Your guess and the actual result. Label both.) + It will print 0, 2, 4, 6,8 + + x = 0 while x < 10: print(x) @@ -20,6 +23,10 @@ 2. What does this program print out? + + It will print 2, 4, 8, 16, 32 + + x = 1 while x < 64: print(x) @@ -27,6 +34,10 @@ 3. Why is the and x >= 0 not needed? + + X is already set to 0 and will never be less than 0 + + x = 0 while x < 10 and x >= 0: print(x) @@ -34,6 +45,10 @@ 4. What does this program print out? (0 pts) Explain. (1 pt) + + Blast off is a string, not an integer, so it will only print 5, 4, 3, 2 ,1, 0 + + x = 5 while x >= 0: print(x)