diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..59fdcf9 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,9 @@ -# +#!/usr/bin/env python3 +#lab_01_part_1.py +#Justin Riebow +#11/2/17 + +"""Asks the user for temperature in fahrenheit and converts it to celsius""" + +fahrenheit = int(input("Enter temperature in Fahrenheit: ")) +print("The temperature in Celsius:", (float((fahrenheit - 32) * 5/9))) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..f5ae92a 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,13 @@ -# +#!/usr/bin/env python3 +#lab_01_part_b.py +#Justin Riebow +#11/2/17 + +"""Prints area of trapezoid""" + +print("Area of a trapezoid") +trapezoidHeight = int(input("Enter the height of the trapezoid: ")) +trapezoidBottomLength = int(input("Enter the length of the bottom base: ")) +trapezoidTopLength = int(input("Enter the lenght of the top base: ")) +trapezoidArea = (0.5 * (trapezoidBottomLength + trapezoidTopLength) * trapezoidHeight) +print("The area is:", (trapezoidArea)) diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..6416dbf 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,13 @@ -# +#!/usr/bin/env python3 +#lab_01_part_c.py +#Justin Riebow +#11/2/17 + +"""Finds the area of a circle""" + +from math import pi +print("Area of a circle") +circleRadius = int(input("Enter the radius of the circle: ")) +circleArea = pi*circleRadius**2 +print(circleArea) + diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..67c11ac 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,69 @@ -# +#!/usr/bin/env python3 +#main_program.py +#Justin Riebow +#11/3/17 + +"""A quiz that asks questions for the user to answer""" + +average = 0 + + +print("Find the sum of: 2(15 + 12) * 4") +answerQ1 = int(input("Answer: ")) +if answerQ1 == 216: + average += 1 + print("Correct!") +else: + print("Incorrect!") + +print("Who was the 16th president of the United States?\nA: George Washington\nB: Abraham Lincoln\nC: Donald Trump\nD: Thomas Jefferson") +answerQ2 = input("Answer: ") +if answerQ2.lower() == "b": + average += 1 + print("Correct!") +elif answerQ2.lower() == "c": + print("... Are you serious?") + q2seriously = input("Y/N: ") + if q2seriously.lower() == "y": + print("How unfortunate. Next Question.") + else: + print("Then who is the 16th president?") + q2seriouslyanswer = input("Answer: ") + if q2seriouslyanswer.lower() == "abraham lincoln": + average += 1 + print("Good. Next question.") + else: + print("You disgust me. Next question.") +else: + print("Incorrect!") + +print("What is the capital of Illinois?") +answerq3 = input("Answer: ") +if answerq3.lower() == "springfield": + average += 1 + print("Correct!") +else: + print("Incorrect!") + +print("You are running a race and you passed the person in second place. What place are you in now?") +answerq4 = input("Answer(without using numbers): ") +if answerq4.lower() == "second" or answerq4.lower() == "second place": + average += 1 + print("Correct!") +else: + print("Incorrect!") + +print("In League of Legends, what is the name of Yasuo's ultimate ability?\nA: Last Breath\nB: Wind Slash\nC: Slice and Dice\nD: Exodia") +answerq5 = input("Answer: ") +if answerq5.lower() == "a": + average += 1 + print("Correct!") +elif answerq5.lower() == "d": + print("Incorrect! Completely different game, but nice try!") +else: + print("Incorrect") + +averagePercent = (average/5) * 100 +print("You got", str(average), "correct.") +print("You got", averagePercent, "percent on this quiz.") + diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..7f10082 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,90 @@ -# +#!/usr/bin/env python3 +#main_program.py +#Justin Riebow +#11/3/17 + +"""bring your car far away enough from the cops to escape before they catch you""" + +import random +done = False +userMiles = 0 +copMiles = 0 +fuel = 8 +thirst = 5 +money = 3 + +print("Welcome to Drive!\nYou have stolen a car to make your way to California.\nThe cops found out and are chasing you down!\nSurvive your road trek and outrun the cops.") +while done == False: + print("A. Grab a drink at the gas station.\nB. Ahead moderate speed.\nC. Ahead full speed\nD. Stop and fuel up\nE. Status check.") + choice = input("Your choice?: ") + if choice.lower() == "q": + done = True + if choice.lower() == "a": + money = money - 1 + thirst = 5 + copMiles = copMiles + random.randint(10, 20) + print("You take a drink.\nYou have enough money for", str(money), "more drinks.") + elif choice.lower() == "b": + userMiles = userMiles + random.randint(7,14) + fuel = fuel - 1 + copMiles = copMiles + random.randint(3, 11) + thirst = thirst - 1 + if thirst == 2: + print("You are thirsty.") + if thirst == 0: + done = True + print("You fainted from dehydration.") + print("You travel at moderate speed.") + if copMiles >= userMiles - 20: + print("The cops are getting close!") + if copMiles >= userMiles: + print("The cops caught you!") + done = True + if fuel <= 2: + print("You are almost out of fuel!") + if fuel <= 0: + print("You ran out of fuel!") + elif choice.lower() == "c": + userMiles = userMiles + random.randint(15, 22) + fuel = fuel - 2 + copMiles = copMiles + random.randint(5, 12) + thirst = thirst - 1 + if thirst == 2: + print("You are thirsty.") + if thirst == 0: + done = True + print("You fainted from dehydration.") + print("You floor it ahead!") + if copMiles >= userMiles - 11: + print("The cops are getting close!") + if copMiles >= userMiles: + print("The cops caught you!") + done = True + if fuel <= 3: + print("You are almost out of fuel!") + if fuel <= 0: + print("You ran out of fuel!") + done = True + elif choice.lower() == "d": + fuel = 8 + copMiles = copMiles + random.randint(10, 20) + print("You fuel up at a gas station") + elif choice.lower() == "e": + print("Miles traveled:", str(userMiles)) + print("How many more drinks you have enough money for:", str(money)) + if thirst >= 4: + print("You are not thirsty.") + if thirst == 3: + print("You are slightly thirsty.") + if thirst == 2: + print("You are thirsty.") + if thirst == 1: + print("You need to drink something ASAP.") + if userMiles >= 200: + copMiles == copMiles - 200 + done = True + print("Congratulations! You escaped the cops!") + + + + diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..5308b5d 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,39 @@ -# +#!/usr/bin/env python3 +#main_program.py +#Justin Riebow +#11/7/17 + +"""A pretty picture""" + +import pygame + +yellow = (235, 244, 66) +lightBlue = (66, 131, 244) +green = (0, 142, 60) +brown = (49, 53, 0) +black = (0, 0, 0) + +pygame.init() + +size = (700, 500) +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("Rainy Day") + +done = False + +clock = pygame.time.Clock() + +while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + screen.fill(lightBlue) + pygame.draw.rect(screen, green, [0, 400, 700, 100 ]) + pygame.draw.rect(screen, brown, [250, 200, 200, 200]) + pygame.draw.polygon(screen, brown, [[350, 100],[250, 200], [450, 200]]) + pygame.draw.rect(screen, black, [325, 325, 50, 75]) + pygame.draw.ellipse(screen, yellow, [20, 20, 100, 100]) + pygame.display.flip() + clock.tick(60) +pygame.quit() diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..c95ac81 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,13 @@ +#!/usr/bin/env python3 +#part_1.py +#Justin Riebow +#11/15/17 +"""Prints out numbers in a certain order""" + +i = 10 +for row in range(1, 10): + for column in range(row): + print(i,end=" ") + i += 1 + print() diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..b2f55ca 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,20 @@ -# +#!/usr/bin/env python3 +#part_2.py +#Justin Riebow +#11/16/17 + +"""Creates a box made of o's""" + +#Make an input for the number of o's in a row +row = int(input("Enter number: ")) +#Draws top line +for toprow in range(row*2): + print("o", end="") +print() +#Draws side +for side in range(row-2): + print("o", (row-2) * " ", "o") +#Draws bottom line +for bottomrow in range(row*2): + print("o", end="") +print () diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..39fd394 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,43 @@ -# +#!/usr/bin/env python3 +#part_4.py +#Justin Riebow +#11/16/17 +"""Create an image using small rectangles""" + +import pygame + +BLUE = (0,0,255) +BLACK = (0,0,0) + +pygame.init() + +size = (500, 500) +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("My Game") + +done = False + +clock = pygame.time.Clock() + +while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + + screen.fill(BLACK) + + for y in range(0, 500, 20): + for x in range(0, 500, 20): + pygame.draw.rect(screen, BLUE, (x, y, 10, 10)) + + pygame.display.flip() + + + clock.tick(60) + +pygame.quit() + + + diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..18a69bc 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,89 @@ -# +#!/usr/bin/env python3 +#main_program.py +#Justin Riebow +#11/20/2017 + +"""A text based adventure game""" + +#Create a list of room descriptions and hooked rooms +room_list=[] +room = ["You are in front of the house.", None, None, 1, None] +room_list.append(room) +room = ["You are in the lobby.", 0, 6, 3, 2] +room_list.append(room) +room = ["You are in a narrow hallway.", None, 1, 4, None] +room_list.append(room) +room = ["You are in a large hallway", 1, 7, None, 4] +room_list.append(room) +room = ["You are in the kitchen.", 2, 3, 5, None] +room_list.append(room) +room = ["You are in the dining room.", 4, None, None, None] +room_list.append(room) +room = ["You are in the garage.", None, None, None, 1] +room_list.append(room) +room = ["You are outside.", None, None, 8, 3] +room_list.append(room) +room = ["You are in the shed.", 7, None, None, None] +room_list.append(room) + +#Set variable for current room +current_room = 0 +done = False + +#Keeps the game running +while not done: + print() + print(room_list[current_room][0]) + #print exits + 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.") + print("What will you do?") + user_input = input(" ").lower() + + #Make north direction + if user_input == "go north" or user_input == "n": + next_room = room_list[current_room][1] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + #Make east direction + elif user_input == "go east" or user_input == "e": + next_room = room_list[current_room][2] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + #Make south direction + elif user_input == "go south" or user_input == "s": + next_room = room_list[current_room][3] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + #Make west direction + elif user_input == "go west" or user_input == "w": + next_room = room_list[current_room][4] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + #quits the game + elif user_input == "quit" or user_input == "q": + done = True + #When the input is invalid + else: + print("Invalid Entry") + + + + diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..5e23020 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,23 +6,36 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. + + print("Justin Riebow") 2. How do you enter a comment in a program? + + Using # 3. What do the following lines of code output? ALSO: Why do they give a different answer? - print(2 / 3) - print(2 // 3) + print(2 / 3) .66 + print(2 // 3) 0 + + the first one gives the decimal and the second one tells you how many times 3 goes into 2 + + 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. + from math import pi + pi = pi + 5. Why does this code not work? A = 22 print(a) + the variable is a capital A and it is trying to print the value of the variable "a" (Capitalization matters) + 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -31,8 +44,10 @@ Area AREA area - area_of_rectangle - Area_Of_Rectangle + + area_of_rectangle <- This is the better variable name because it is the most descriptive and doesn't using capitalization + + 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 @@ -42,12 +57,12 @@ Apple APPLE Apple2 - 1Apple + 1Apple - not allowed account number account_number - account.number + account.number - not allowed accountNumber - account# + account# - not allowed pi PI fred @@ -55,21 +70,25 @@ GreatBigVariable greatBigVariable great_big_variable - great.big.variable - 2x + great.big.variable - not allowed + 2x - not allowed x2x - total% - #left + total% - not allowed + #left - not allowed 8. Why does this code not work? print(a) a = 45 + it's trying to print the variable before it is read so it technically doesn't exist + 9. Explain the mistake in this code: pi = float(3.14) + you cannot float a decimal because float turns it into a decimal + 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) + Instead of doing "x = 3.14" and "pi = x" it could just say "pi = 3.14" + 11. Explain the mistake in the following code: x = 4 @@ -86,6 +107,8 @@ a = ((x) * (y)) print(a) + the x and y do not need parentheses around them individually + 12. Explain the mistake in the following code: x = 4 @@ -93,36 +116,56 @@ a = 3(x + y) print(a) + the 3 will not multiply with the x and y without using * + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) + It should be int(input("Enter the radius:")) + 14. Do all these print the same value? Which one is better to use and why? print(2/3+4) print(2 / 3 + 4) print( 2 / 3+ 4 ) + they all come out the same but the better one to use is the one without spaces + 15. What is a constant? + + a value that stays the same 16. How are variable names for constants different than other variable names? + + they are usual one word and less descriptive 17. What is a single quote and what is a double quote? Give and label an example of both. + + Single quote = 'this is a single quote' Double quote = "this is a double quote" 18. Write a Python program that will use escape codes to print a double-quote and a new line using the Window's standard. (Note: I'm asking for the Window's standard here. Look it up out of Chapter 1.) + + print("\"\n") 19. Can a Python program print text to the screen using single quotes instead of double quotes? + + Yes 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) + it first divides 5 by three then adds it all together. It needs to put the addition in parentheses so it does that first + 21. What is an ``operator'' in Python? + + operators modify numbers 22. What does the following program print out? @@ -130,16 +173,20 @@ x + 1 print(x) - +it will print 3 + 23. Correct the following code: user_name = input("Enter your name: )" + user_name = input("Enter your name: ") + 24. Correct the following code: value = int(input(print("Enter your age"))) - +value = int(input("Enter your age")) +age = print(value) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..44f91ef 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,88 @@ 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.) + + 0101 2. Give an example of a decimal number. + + 1.7 3. Give an example of a hexadecimal number. + + 64AC 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. + + 1, 2, 4, 8, 16 5. What is a compiler? + + "A computer software that transforms computer code written in one programming language into another computer language" 6. What is source code? + + "a text listing of commands to be compiled or assembled into an executable computer program" 7. What is machine language? (Don't just say binary. That's not correct.) + + machine language is a language that a comptuer can respond to directly 8. What is a first generation language? (Don't just say binary. That's not correct.) + + "machine-level programming language" 9. What is a second generation language? + + "generational way to categorize assembly langauges" 10. What is a third generation language? (Explain, don't just give one example.) + "generational way to categorize high-level computer programming languages" + 11. What is an interpreter and how does it differ from a compiler? + + "an interpreter is a compter program tha tdirectly executes instructions written in a programming or scripting language without + requiring them previously to have been compiled into a machine langauge program" 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 + + https://www.inc.com/larry-kim/10-most-popular-programming-languages-today.html 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. + + SQL + Java + JavaScript + C# + Python + C++ + PHP + IOS + Ruby/Rails + + http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2016/ 14. What is the difference between the ``syntax'' and ``semantics'' of a language? + + "Syntax refers to grammatical structure whereas the term semantics refers to the meaning of the vocabulary symbols arranged with that structure" 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. + + My iphone uses a Apple A6 processor. It uses IOS as the operating system diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..721c460 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,13 +10,28 @@ print("It is hot outside.") else: print("It is not hot out.") + + It is missing a second ")" at the end of the first line of code 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("The number is negative.") + elif number == 0: + print("The number is zero.") + else: + print("The number is postive.") 3. Write a Python program that will take in a number from a user and print out ``Success'' if it is greater than -10 and less than 10, inclusive. (1 pt) + + number = int(input("Enter a number: ")) + if number > -10 and number < 10: + print("Success") + 4. This runs, but there is something wrong. What is it? (1 pt) @@ -27,6 +42,8 @@ print("Correct!") else: print("Incorrect.") + + the two print statements should be above the input so that the user can see the choices before they put in 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. @@ -39,11 +56,20 @@ else: print("x is not positive.") + the first variable should be written "x = 4" + the code wouldn't work because any negative number is greater than or equal to 4, so it would say that it is positive. + + 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") + + x should be an integer + line 2 should read "if x == 3" + there should be a ":" at the end of line 2 + 7. There are four things wrong with this code. Identify all four issues. (4 pts) @@ -52,6 +78,10 @@ print("Correct!") else print("Incorrect! It is Beaker.") + + 2nd line has two problems. the variable should be answer, not a. it should also say "==" instead of "=" + "else" should not be indented + the else statement needs a ":" after it 8. This program doesn't work correctly. What is wrong? (1 pt) @@ -59,6 +89,8 @@ if x == "Happy" or "Glad": print("That is good to hear!") + after "or" it needs to say "x == "Glad":" + 9. Look at the code below. Write you best guess here on what it will print. Next, run the code and see if you are correct. Clearly label your guess and the actual answer. @@ -78,6 +110,8 @@ print("Fizz") if z: print("Buzz") + + I guess that it will print 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) @@ -97,6 +131,18 @@ print(x == 5 and y == 5) print(x == 5 or y == 5) + 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) @@ -129,6 +175,10 @@ money = 70 else if user_input = C: money = 50 + + in the if statements the letters need to have quotes around them + an accumulator called money needs to be made + the else if statements should say "elif" diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..d1c32bc 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,17 +13,38 @@ 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 = "Justin Riebow" + for letter 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.) + + red = "Red" + gold = "Gold" + for color in range(20): + print(red) + print(gold) + print("Done") 3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive. + for number in range(2,101,2): + print(number) + 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. + + number = 11 + while number > 0: + number = number - 1 + print(number) + print("Blast off!") 5. There are three things wrong with this program. List each. (3 pts) @@ -35,12 +56,23 @@ total = total + i print("The total is:", x) + it should print total, not x + + + 6. Write a program that prints a random integer from 1 to 10 (inclusive). + + import rando + print(random.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. + import random + randomNumber = random.randint(1,10) + print(float(randomNumber)) + 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -49,6 +81,25 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. + total = 0 + positive = 0 + negative = 0 + zero = 0 + + for number in range(7): + user_number = int(input("Enter a number: ")) + total += user_number + if user_number < 0: + negative = negative + 1 + elif user_number > 0: + positive = positive + 1 + else: + zero = zero + 1 + print("Numbers that are zero:", str(zero)) + print("Negative numbers:", str(negative)) + print("Postive numbers:", str(positive)) + print("Total:", total) + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +108,20 @@ * 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): + randomNumber = random.randint(0, 1) + if randomNumber == 0: + heads = heads + 1 + print("Heads") + if randomNumber == 1: + tails = tails + 1 + print("Tails") + print("Number of Heads:", heads) + print("Number of Tails:", tails) + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -66,4 +131,24 @@ * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. + import random + user_choice = int(input("Rock(1), Paper(2), or Scissors(3)? ")) + randomNumber = random.randint(1, 3) + if randomNumber == 1: + print("Rock") + if randomNumber == 2: + print("Paper") + if randomNumber == 3: + print("Scissors") + + if user_choice == randomNumber: + print("It's a tie!") + elif user_choice == 3 and randomNumber == 2: + print("You win!") + elif user_choice == 2 and randomNumber == 1: + print("You win!") + elif user_choice == 1 and randomNumber == 3: + print("You win!") + else: + print("You lose!") diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..d3b0cbf 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -8,21 +8,38 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + The y coordiantes are reversed. + the computer system covers the lower right quadrant while the cartesian system usually focuses on the upper 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 + pygame.init() + 3. Explain how WHITE = (255, 255, 255) represents a color. + + It uses red green and blue 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 signify variables that are constants by naming them with all upper-case letters. + if it is likely to change we use lower-case letters. + 5. What does the pygame.display.set_mode() function do? + Opens a window + 6. What does this for event in pygame.event.get() loop do? + It handles all the keystrokes, mouse clicks, and other types of events + 7. What is pygame.time.Clock used for? + it is used to limit FPS + 8. For this line of code: (3 pts) pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5) @@ -32,10 +49,18 @@ * What does [100, 100] do? * What does 5 do? - + Draws on the screen + Determines origin point + Determines end point + Determines how many pixels wide it will be + 9. What is the best way to repeat something over and over in a drawing? + + using a loop 10. When drawing a rectangle, what happens if the specified line width is zero? + + It will cover 0 pixels 11. Describe the ellipse drawn in the code below. * What is the x, y of the origin coordinate? @@ -45,23 +70,39 @@ pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) + It starts at coordinates 20, 20 and ends at coordinates 250, 100 and it is 2 pixels wide + 12. When drawing an arc, what additional information is needed over drawing an ellipse? + + It needs start and end angles 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + + First, the program creates a variable that holds information about the font to be used + Second, the program creates an image of the text + Third, The program tells where this image of the text should be stamped 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 that it doesn't keep repeating itself and popping up all over 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) + It will be a rectangle + 16. What does pygame.display.flip() do? + adds all of the changes you put into the code + 17. What does pygame.quit() do? + + exits the screen and stops the code 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 diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..0699a08 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,9 @@ while x < 10: print(x) x = x + 2 + + it will print 0,2,4,6,8 on seperate lines + it prints 0,2,4,6,8 all on seperate lines 2. What does this program print out? @@ -25,12 +28,17 @@ print(x) x = x * 2 + it will print 1,2,4,8,16,32 on seperate lines + it prints 1,2,4,8,16,32 on seperate lines + 3. Why is the and x >= 0 not needed? x = 0 while x < 10 and x >= 0: print(x) x = x + 2 + + You don't need to check for things that can never be false 4. What does this program print out? (0 pts) Explain. (1 pt) @@ -40,6 +48,8 @@ if x == "1": print("Blast off!") x = x - 1 + + it prints 5, 4, 3, 2, 1, 0 on seperate lines because there are quotations around the number 1 making it a string 5. Fix the following code so it doesn't repeat forever, and keeps asking the user until he or she enters a number greater than zero: (2 pts) @@ -49,6 +59,8 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") + instead of print it should use input + 6. Fix the following code: x = 10 @@ -59,13 +71,28 @@ print("Blast-off") + It should be: + + x = 10 + + while x > 0: + print(x) + x = x - 1 + + print("Blast-off") + + It should say while x is greater than 0, not less than. x - 1 wouldn't work as it would only make it 9. + 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) i = 0 for i in range(10): print(i) - i += 1 + i += + + You do not have to define i + The for loop sets i 8. Explain why the values printed for x are so different. (2 pts) @@ -86,3 +113,4 @@ print(x) +Sample 2 has a nested for loop, making j run 10 times while Sample 1 is not nested making each run only once