diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..d7420f9 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,19 @@ # +#!/usr/bin/env python3 + +#Converting Fahrenheit to Celcius + +#Jordan Watt + +#11-2-17 + + + +"""Converting Fahrenheit to Celcuis""" + + + +#Letting the User Define the Temperature + + + +tempF = int(input('Enter temperature in Fahrenheit: ')) + + + +#Using the conversion forumula for Fahrenheit to Celcuis + + + +tempC = (tempF - 32) * (5/9) + + + +#print to console + + + +print('The temperature in Celsius: ', tempC) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..383a5be 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,26 @@ # +#!/usr/bin/env python3 + +#Trapezoid Area + +#Jordan Watt + +#11-2-17 + + + +"""Using the Height and length of the top & bottom base of the Trapezoid we can find the area""" + + + +#Title + + + +print('Area of a trapezoid') + + + +#define height, and length of Top & Bottom + + + +height = int(input('Enter the height of the trapezoid: ')) + +botLength = int(input('Enter the length of the bottom base: ')) + +topLength = int(input('Enter the length of the top base: ')) + + + +#Formula + + + +area = .5*(topLength + botLength)*height + + + +#print + + + +print('The area is:',area) +View diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..ba3fab3 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,23 @@ # +#!/usr/bin/env python3 + +#Circle Area + +#Jordan Watt + +#11-2-17 + + + +"""Using the radius to find the Area of a circle""" + + + +#import math + + + +from math import pi + + + +#user input for radius + + + +radius = int(input('Enter the radius: ')) + + + +#Equation + + + +area = pi*radius**2 + + + +#print + + + +print('The area is:', area) diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..6230b4a 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,66 @@ # +#!/usr/bin/env python3 + +#Quizz + +#Jordan Watt + +#11-3-17 + + + +"""Create a quiz that is 5 questions long""" + + + +#Accumulator for points + + + +total = 0 + + + +#Question 1 [numbers] + + + +qOne = int(input('How many bits are in a byte? ')) + +if qOne == 8: + + total += 1 + + print('Correct!') + +else: + + print('EERRNNGGG!!!') + +print('') + + + +#Question 2 [selection] + + + +qTwo = input('What is the name of Master Cheifs home planet?\nD-"Eridanus II"\n') + +if qTwo.lower() == 'c': + + total += 1 + + print('Correct!') + +else: + + print('EERRNNGGG!!!') + +print('') + + + +#Question 3 [text] + + + +qThree = input('What is the name of the national anthem? ') + +if qThree.lower() == 'the star spangled banner': + + total += 1 + + print('Correct!') + +else: + + print('EERRNNGGG!!!') + +print('') + + + +#Question 4 [number] + + + +qFour = int(input('"Sally sold seashells by the seashore,\nIf Sally sold seashells by the seashore,\nHow many seashells did sally sell?",\nHow many words start with s? ')) + +if qFour == 11: + + total += 1 + + print('Correct!') + +else: + + print('EERRNNGGG!!!') + +print('') + + + +#Question 5 [text] + + + +qFive = input('What is the name of the "Gray Wizard",\nin the Lord of the Rings? ') + +if qFive.lower() == 'gandalf': + + total += 1 + + print('Correct!') + +else: + + print('EERRNNGGG!!!') + +print('') + + + +#Calculating Percentage + + + +perc = (total / 5) * 100 + +print(str(perc) + '%') diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..ffe7c72 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,121 @@ # +#!/usr/bin/env python3 + +#Space Smuggler + +#Jordan Watt + +#11-6-17 + + + +"""You stolen a camel and must fight, nature and man to survive!""" + + + +#Imports + + + +import random + + + +#Accumulators + + + +miles = 0 + +hunger = 0 + +fuel = 6 + +Empire = -20 + +rations = 4 + + + +#Introduction + + + +print('\nWelcome to Space Smuggler!\n\nYou have stolen a space ship to make your way across the Outer Rim.\nThe Empire want their space ship back and are chasing you down!\nSurvive your space trek and out run NASA.\n') + + + +#While choices + + + +done = False + +while done == False: #Choices + + + + #most-recent + + + + oasis = random.randint(1, 21) + + nasatra = random.randint(7, 15) + + milestra = random.randint(10, 21) + + + + print('A. Open a bag of rations.\nB. Ahead moderate speed.\nC. Ahead full speed.\nD. Stop for the night.\nE. Status check.\nQ. Quit.') + + user_choice = input('Your choice? ') + #Quits Game + + + + if user_choice.upper() == 'Q': + + done = True + + + + #Check Status + + + + elif user_choice.upper() == 'E': + + print('\nMiles traveled: ' + str(miles) + '\nRations left:' + str(rations) + '\nNASA is', str(nasa * -1), 'miles behind you.') + + + + #Stop for the night + + + + elif user_choice.upper() == 'D': + + fuel = 3 + + print('\nYou found more fuel!') + + Empire = Empire - (milestra - nasatra) + + + + #Full Speed + + + + elif user_choice.upper() == 'C': + + miles = miles + milestra + + print('\nYou traveled:', str(milestra), 'miles\n') + + hunger += 1 + + fuel = fuel - random.randint(1, 4) + + Empire = Empire - (milestra - nasatra) + + + + #Moderate Speed + + + + elif user_choice.upper() == 'B': + + miles = miles + random.randint(5, 13) + + print('\nYou traveled:', str(milestra), 'miles\n') + + hunger += 1 + + fuel -= 1 + + Empire = Empire - (milestra - nasatra) + + + + #Eat Rations + + + + elif user_choice.upper() == 'A': + + if rations != 0: + + rations -= 1 + + hunger = 0 + + else: + + print('No rations left!\n') + + + + #Conditons: + + #Hunger + + + + if hunger >= 4: + + print('You are hungry!\n') + + if hunger > 6: + + print('You died of starvation!\n') + + done = True + + + + #Fuel + + + + if -3 < fuel <= 0: + + print('Your running on fumes!\n') + + if -3 >= fuel: + + print('Your ship ran out of gas\nThe Empire caught you :(\n') + + done = True + + continue + + + + #NASA + + + + if Empire >= 0: + + print('The Empire has caught you!\n') + + done = True + + continue + + elif 0 > Empire >= -15: + + print('The Empire is gaining on you!\n') + + + + #Winning + + + + if miles >= 200: + + print('YOU MADE IT ACROSS THE OUTER RIM!!!\n') + + + + #Oasis + + + + oasis = random.randint(1, 21) + + if oasis == 2: + + print('You found the Rebel Alliance!\n') + + hunger = 0 + + fuel = 3 + + rations = 4 diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..49ca03b 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,106 @@ -# +#!/usr/bin/env python 3 +#Destroy The City PyGame +#Jordan Watt +#11-9-17 + >>>>>>> d65a200f26d213f86446b9aa3fa7733773ae286a + + import pygame + + WHITE = (255, 255, 255) + GREEN = (144, 212, 178) + PINK = (209, 21, 184) + BLUE = (75, 51, 232) + YELLOW = (226, 232, 51) + BLACK = (0, 0, 0) + BROWN = (87, 59, 23) + PI = 3.141592653 + + 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("Destroy The City") + + # 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 + + # If you want a background image, replace this clear with blit'ing the + # background image. + screen.fill(BLACK) + + # Draw a rectangle + pygame.draw.rect(screen, BLUE, [120, 150, 100, 200]) + pygame.draw.rect(screen, BLUE, [470, 150, 100, 200]) + pygame.draw.rect(screen, GREEN, [580, 150, 100, 200]) + pygame.draw.rect(screen, GREEN, [10, 150, 100, 200]) + # The top row of 'windows' on the buildings + pygame.draw.rect(screen, YELLOW, [20, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [70, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [130, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [180, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [480, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [530, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [590, 170, 30, 20]) + pygame.draw.rect(screen, YELLOW, [640, 170, 30, 20]) + # The middle row of 'windows' on the buildings + pygame.draw.rect(screen, YELLOW, [20, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [70, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [130, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [180, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [480, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [530, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [590, 220, 30, 20]) + pygame.draw.rect(screen, YELLOW, [640, 220, 30, 20]) + # The bottom row of 'windows' on the buildings + pygame.draw.rect(screen, YELLOW, [20, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [70, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [130, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [180, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [480, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [530, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [590, 270, 30, 20]) + pygame.draw.rect(screen, YELLOW, [640, 270, 30, 20]) + # The 'doors' on the buildings' + pygame.draw.rect(screen, BROWN, [35, 300, 50, 50]) + pygame.draw.rect(screen, BROWN, [145, 300, 50, 50]) + pygame.draw.rect(screen, BROWN, [495, 300, 50, 50]) + pygame.draw.rect(screen, BROWN, [605, 300, 50, 50]) + + # Draw an arc as part of an ellipse. + # Use radians to determine what angle to draw. + pygame.draw.arc(screen, WHITE, [220, 150, 250, 200], 0, PI / 2, 2) + pygame.draw.arc(screen, GREEN, [220, 150, 250, 200], PI / 2, PI, 2) + pygame.draw.arc(screen, BLUE, [220, 150, 250, 200], PI, 3 * PI / 2, 2) + pygame.draw.arc(screen, YELLOW, [220, 150, 250, 200], 3 * PI / 2, 2 * PI, 2) + + # Select the font to use, size, bold, italics + font = pygame.font.SysFont('Calibri', 25, True, False) + + # Render the text. "True" means anti-aliased text. + # White is the color. This creates an image of the + # letters, but does not put it on the screen + text = font.render("Button to Destroy All", True, WHITE) + + # Put the image of the text on the screen at 245x240 + screen.blit(text, [245, 240]) + + pygame.display.flip() + + # --- Limit to 60 frames per second + clock.tick(60) + + # Close the window and quit. + <<<<<<< HEAD + pygame.quit() + ======= + pygame.quit() diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..9ca3036 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,23 +6,23 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. - + Answer:print("Jordan Watt") 2. How do you enter a comment in a program? - + Answer:# 3. What do the following lines of code output? ALSO: Why do they give a different answer? print(2 / 3) print(2 // 3) - + Answer:(2 / 3) = 0.66 (2 // 3)= 0 The reason they are different is because florr division rounds it while regular division doesn't 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. - + pi = 3 5. Why does this code not work? A = 22 print(a) - + Answer:Because the variable being called to print is not defined, it needs to be uppercased if it is to work. 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -33,7 +33,7 @@ area area_of_rectangle Area_Of_Rectangle - + Answer: area_of_rectangle 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.) @@ -43,11 +43,11 @@ APPLE Apple2 1Apple - account number + account number account_number account.number accountNumber - account# + account# pi PI fred @@ -58,19 +58,19 @@ great.big.variable 2x x2x - total% - #left - + total% + #left + Answer: account number because you cannot have spaces 8. Why does this code not work? print(a) a = 45 - + Answer: Because the print statement needs to be after the variable got set to a value. 9. Explain the mistake in this code: pi = float(3.14) - - 10. This program runs, but the code still could be better. Explain what is + Answer: the 3.14 is unnecessary since it already is a float. + 10. This program runs, but the code still could be better. Explain what is wrong with the code. radius = float(input("Radius:")) @@ -78,68 +78,71 @@ pi = x area = pi * radius ** 2 print(area) - + Answer: you could get rid of the variable x entirely. 11. Explain the mistake in the following code: x = 4 y = 5 a = ((x) * (y)) - print(a) - + print(a) + Answer: There is multiple statements found while compiling a single statement. 12. Explain the mistake in the following code: x = 4 y = 5 a = 3(x + y) print(a) - + Answer: There is multiple statements found while compiling a single statement. 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) - + Answer: They called for radius to be printed 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 ) - + Answer: Yes they print the same value. The second one is the best because you don't want too many spaces but you do want some so it is not so clustered. 15. What is a constant? - + A variable that stays the same. 16. How are variable names for constants different than other variable names? - + Answer: A constant stays the same but a constant 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.) + Answer: print('""'/n) 19. Can a Python program print text to the screen using single quotes instead of double quotes? - + Answer: Yes 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) - + Answer: It does division first because of order of operations 21. What is an ``operator'' in Python? - + Answer:An operator is a character that represents an action, 22. What does the following program print out? x = 3 x + 1 print(x) - + Answer: 3 23. Correct the following code: user_name = input("Enter your name: )" - + Answer:username =input('Enter you name: ') + print(username) 24. Correct the following code: value = int(input(print("Enter your age"))) - + Answer:int(input("Enter your age: ")) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..4d8492e 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,30 +6,30 @@ 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.) - + Answer: 101101 2. Give an example of a decimal number. - + Answer: 82 3. Give an example of a hexadecimal number. - + Answer: 3FA 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. - + Answer: 1 = 1, 10 = 2, 100 = 4, 1000 = 8, 10000 = 16 5. What is a compiler? - + Answer: Converts source code into machine code 6. What is source code? - + Answer: The program the developer types into the computer 7. What is machine language? (Don't just say binary. That's not correct.) - + Answer: The native code ran by the computer 8. What is a first generation language? (Don't just say binary. That's not correct.) - + Answer:Machine language 9. What is a second generation language? - + Answer: Assembly language 10. What is a third generation language? (Explain, don't just give one example.) - + Answer: Python, C logical structure. 11. What is an interpreter and how does it differ from a compiler? - + Answer:An interpreter and a compiler are almost the same thing, except a 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. - + Answer: Java, python, Javascript, Ruby, C, C+, and 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. diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..77b6667 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,14 +10,27 @@ print("It is hot outside.") else: print("It is not hot out.") - + Its missing the second parentheses at the end. 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. + userNum = int(input('Choose a number: ')) + if userNum > 0: + print('Your Number is positve') + elif userNum < 0: + print('Your Number is negative') + else: + print('Your Number is Zero') + 3. Write a Python program that will take in a number from a user and print out ``Success'' if it is greater than -10 and less than 10, inclusive. (1 pt) - + userNum = int(input('Choose a number: ')) + if -10 > userNum > 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,7 +40,7 @@ print("Correct!") else: print("Incorrect.") - + The Choices print after the user answers the question, with no prompt. 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,12 +52,13 @@ else: print("x is not positive.") + There does not need to be two equal signs in front of x to set it to 4. The other is that the user doesnt choose a value for x. 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") - + There needs to be two equal signs in the if statement, no colon after the if statement, and no int() in the x definition. 7. There are four things wrong with this code. Identify all four issues. (4 pts) answer = input("What is the name of Dr. Bunsen Honeydew's assistant? ") @@ -52,13 +66,14 @@ print("Correct!") else print("Incorrect! It is Beaker.") + In the if statment it does not call for 'answer', The else is not indented correctly, no colon after else, and there is no two equal signs in the if statment. 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!") - + Or is not used correctly [Plus there is no space after the '?'] 9. Look at the code below. Write you best guess here on what it will print. Next, run the code and see if you are correct. Clearly label your guess and the actual answer. @@ -78,7 +93,8 @@ print("Fizz") if z: print("Buzz") - + My Guess: x= 5, y= 5, z= 5, Buzz + Anwser: x= 5, y= False, z= True, Buzz 10. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts) @@ -109,7 +125,8 @@ print( (2 == 2) == "True" ) print( (2 == 2) == True ) print(3 < "3") - + My Guess: True, False, False, False, True, False, False, True, False, True + Anwser: True, False, True, False, False, True, False, False, True, False, True 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -130,6 +147,6 @@ else if user_input = C: money = 50 - + Not using double equal signs, the user might put a lowercase letter, no space after user_input question, uses else if instead of elif and else diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..5470d43 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -1,7 +1,6 @@ - + Chapter 04 Worksheet - Reminder: Please use full sentences, capital letters, and proper grammar where appropriate. Don't create a loop that only loops once. That doesn't make sense. @@ -13,18 +12,29 @@ 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('What is 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. - +countdown = 10 +while countdown != 0: + print(countdown) + countdown -= 1 +print(countdown) +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 +44,16 @@ x = input("Enter a number: ") total = total + i print("The total is:", x) - + Will not print total but print x, also the program doesnt take 3 numbers it takes numbers 0,1,2 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. - +for top in range(0, 11): + print(float(top)) 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -48,7 +61,22 @@ * Print the count of the positive entries, the number entries equal to zero, and the number of negative entries. Use an if, elif, else chain, not just three if statements. - + total = 0 + pos = 0 + zeros = 0 + neg = 0 + numba = input('Enter 7 numbers') + numba = numba.split() + for number in numba: + total = total + int(number) + if int(number) > 0: + pos += 1 + elif int(number) < 0: + neg += 1 + else: + zeros += 1 + print(total) + print(pos, zeros, neg, sep='\n') 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -56,7 +84,16 @@ using if statements. Don't select from a list, as shown in the chapter. * Add a loop so that the program does this 50 times. * Create a running total for the number of heads flipped, and the number of tails. - +import random +heads = 0 +tails = 0 +for flips in range(50): + number = random.randint(0,2) + if number == 1: + tails += 1 + else: + heads += 1 + print(‘Heads:’,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. @@ -65,5 +102,32 @@ * Add to the program so it first asks the user their choice. * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. - +import random +for Choice in range(2): +number = random.randint(0,3) +if number == 0: + comp = 'scissors' +elif number == 1: + comp = 'rock' +else: + comp = 'paper' +player = input('Rock\nPaper\nScissors\nChoose: ') +if player.lower() == comp: +print('Its a draw!') +else: +if comp == 'scissors': + if player == 'rock': + print('You Win!') + else: + print('My scissors beat your', player) +elif comp == 'rock': + if player == 'paper': + print('You Win!') + else: + print('My rock beat your', player) +else: + if player == 'scissors': + print('You Win!') + else: + print('My paper beat your', player) diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..15dc74a 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -7,22 +7,22 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. - +The computer coordinate system is different from the standard Cartesian coordinate system in the sense that the y coordinats are reversed in the Catesian system, and the computer coordinate system focuses on the bottom right quadrant, while Catesian focuses on top right quadrant. 2. Before a Python Pygame program can use any functions like pygame.display.set_mode(), what two lines of code must occur first? - +import pygame and pygame.init() 3. Explain how WHITE = (255, 255, 255) represents a color. - +This represents a color because it tells the computer to put as much color as possible on display, creating white as the three colors (RGB) are combined. The numbers are what specify how much of what color is going to be put in. 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.) - +We make them all uppercase because colors are constants, and we do not expect them to change in any way. 5. What does the pygame.display.set_mode() function do? - +The pygame.dsiplay.set_mode() function removes everything off of the screen, and gives the game control of the screen. It also helps to place a pre-determined size of the screen. 6. What does this for event in pygame.event.get() loop do? - +This loop helps process all the keystroke, mouse button clicks, or any other type of event. 7. What is pygame.time.Clock used for? - + pygame.time.Clock is used to manage how fast a screen updates. 8. For this line of code: (3 pts) pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5) @@ -31,12 +31,12 @@ * What does [0, 0] do? * What does [100, 100] do? * What does 5 do? - + he screen is where the green line is being drawn on. The [0, 0] is where the line starts, and [100, 100] is where it ends. The 5 represents how many pixels wide the line is meant to be. 9. What is the best way to repeat something over and over in a drawing? - +The best way to repeat a drawing is a 'for' or 'while' loop, but you also must use 'y_offset' 10. When drawing a rectangle, what happens if the specified line width is zero? - + The rectangle then will not have a border around it and will be instead filled with the specified color. 11. Describe the ellipse drawn in the code below. * What is the x, y of the origin coordinate? * What does the origin coordinate specify? The center of the circle? @@ -44,25 +44,25 @@ pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) - + The origin coordinate for x is [20, 20] and the origin coordinate for y is [250, 100]. The origin coordinate specifies where in the upper left of the rectangle the ellipse. The length of the ellipse is 100, and the width is 100 pixels. 12. When drawing an arc, what additional information is needed over drawing an ellipse? - +The two things that are added in the information needed for an arc is the starting and ending angles for the arc 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? - +The 3 steps are the pygame.font.SysFont(), font.render() and screen.blit() functions. 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. - + This line only needs to run once because the font type and sizing is accepted as a constant, and not expected to change, so there is no point in running it multiple times. 15. What are the coordinates of the polygon that the code below draws? pygame.draw.polygon(screen, BLACK, [[50,100],[0,200],[200,200],[100,50]], 5) - + This line only needs to run once because the font type and sizing is accepted as a constant, and not expected to change, so there is no point in running it multiple times. 16. What does pygame.display.flip() do? - +it flips the programs display screen 17. What does pygame.quit() do? - +It quits the program or ends it 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.