diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..4fdac7a 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,4 @@ -# +# This will transfer Fahrenheit to Celsius +fahrenheit = int(input('Enter temperature in Fahrenheit: ')) +fahrenheit = (fahrenheit -32) * 5/9 +print('The temperature in Celsius:', fahrenheit) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..e7d7fd2 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,8 @@ -# +# This will print the area of a trapezoid +print('Area of a trapezoid') +height = int(input('Enter the height of the trapezoid: ')) +bottomLength = int(input('Enter the length of the bottom base: ')) +topLength = int(input('Enter the length of the top base: ')) +area = 1/2 * (bottomLength + topLength) * height +print('The area is:', area) + diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..0b7a0ad 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,5 @@ -# +# This will print the area of a circle +print('Area of a circle') +radius = int(input('Enter the radius: ')) +area = 3.14 * (radius**2) +print('The area is:', area) 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..f90d9f8 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,11 @@ -Report goes here +Name: Lyles +Date: November 8, 2017 +Video Name: Triumph of the Nerds + +Woops? + The “Triumph of the Nerds” is a documentary about the history behind computers and programming. The settings they had chosen for each ‘scene’ of the film intrigued me from the beginning. + They began the film at a basketball game. I learned they were there due to the man, Paul Allen, who owned the building and basketball team. It turns out he had worked together with Bill Gates, who I had previously thought worked alone (or at least mainly with the idea of Microsoft solely). Both of them were the creators of the Microsoft company, but Bill Gates is obviously more well known as its’ CEO. Microsoft’s original creation was based to make software for the Altair 8800, which I found interesting as they started off at something so simple yet now Microsoft is one of the biggest computer companies around the world. + Shortly into the documentary, they had a section where they were showing off this young boy who had been into computers and technology ever since he was little. One of the things they had stated was that computing was a “boy thing”, as there were never girls around or interested in this type of thing. I believe this was and is very wrong, there most likely was women and girls interested but were unable to be a part of it due to certain/different circumstances. Grace Hopper helped prove this “boy thing” wrong. She had created the first computer language, called Coball, which I thought was a strange name and wonder how she came up with it. Computers and programming has and will continue getting better with the help of women. Society has improved immensely on the treatment and inclusion of women in environments and careers that are typically male-dominated. + “Triumph of the Nerds” also spoke about how the Altair 8800 came to be. It was created when Robert’s company, MITS, was going under in debt. The Altair 8800 was hyped up and seen as this amazing invention before it even started selling. The film’s narrator showed the 2nd made Altair 8800. This was because when the 1st Altair 8800 was sent to have its’ photo taken for a magazine, it got lost in the mail. I thought that was really interesting and quite funny because this huge invention is ready to be announced and sell to people, and it just gets lost. I was curious to see if the 1st Altair 8800 was ever found, but unfortunately it had been shipped when Railway Express had went on strike and eventually bankrupt, losing the computer forever. Afterwards, though, MITS began selling the Altair 8800 and it skyrocketed. Sales were over 200 everyday, and Robert’s could finally pay off his debts. + Something that caught my eye was the coder’s process and their living environment. They all basically lived together in their programming offices, and lived off of bad hygiene, coca-cola, and cold pizza. There was no certain schedule of when they had to work and when their breaks were, they just simply had to work the 80 hours per week. Personally, I find it gross whenever they had said that they didn’t like anything that took away time from programming, such as showering or other hygienics, because while programming is big and amazing you still need to take care of your body and your health. Coca-cola and cold pizza diets certainly did not help, but I cannot talk because I also eat lots of fast food, and drink Dr. Pepper daily. The programmers, though, would constantly share their finds or problems throughout the process of making them. This helped make it possible to have the huge sharing we have between programmers and coders today, like how we also pair up for projects. + Lastly, the main thing that I really enjoyed was the fact this all started with an accident that was made attempting to impress friends. Life is unexpected, and we do things that we didn’t expect or want to do, but sometimes this can lead to amazing things. Gates and Allen are both billionaires due this “accident.” Just because something doesn’t necessarily go your way at the start doesn’t mean it won’t work out in the end. People will always find a way to fix problems, and better today’s technology and society. Accidents aren’t always accidents. diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..b3c77ed 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,57 @@ # +print("Welcome to Lyles' Quiz!") +result = 0 +question1 = print('Question 1: What is 4 + 2?') +print('A. 4') +print('B. 2') +print('C. 6') +answer1 = input('Answer: ') +if answer1 == 'C': + print('Correct') + result = result + 1 +else: + print('Incorrect') + + + +question2 = print('Question 2: What does USA stand for?') +print('A. United States America') +print('B. United States of America') +print('C. Undergoing Software Adaptations') +answer2 = input('Answer: ') +if answer2 == 'B': + print('Correct') + result = result + 1 +else: + print('Incorrect') +question3 = print("Question 3: Who is North Korea's leader?: ") +print('A. Kim Jong-un') +print('B. Donald Trump') +print('C. Trick Question?') +answer3 = input('Answer: ') +if answer3 == 'A': + print('Correct') + result = result + 1 +else: + print('Incorrect') +question4 = print('What is 43 times 2?: ') +print('A. 87') +print('B. 85') +print('C. 86') +answer4 = input('Answer: ') +if answer4 == 'C': + print('Correct') + result = result + 1 +else: + print('Incorrect') +question5 = print('Which actor was in "The Breakfast Club"?') +print('A. Judd Nelson') +print('B. Brad Pitt') +print('C. Megan Fox') +answer5 = input('Answer: ') +if answer5 == 'A': + print('Correct') + result = result + 1 +else: + print('Incorrect') +print('Total Answers Correct:', result) diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..30dc6f8 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,69 @@ -# +#Camel Coding Game + +print('Welcome to Camel!') +print('You have stolen a camel to make your way across the great Mobi desert.') +print('The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.') + +traveledMiles = 0 +thirst = 0 +camelTiredness = 0 +nativesTraveled = -20 +canteenDrinks = 20 +import random + +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.') + user_choice = input('What is your choice? ') + if user_choice.upper() == 'Q': + done = True + elif user_choice.upper() == 'E': + print('Miles traveled:', traveledMiles) + print('Drinks in canteen:', canteenDrinks) + print('The natives are', nativesTraveled, 'miles behind you.') + elif user_choice.upper() == 'D': + camelTiredness = 0 + print('The camel is happy!') + nativesTraveled += random.randint(7, 15) + elif user_choice.upper() == 'C': + traveledMiles += random.randint(10, 21) + print('Miles traveled:', traveledMiles) + thirst += 1 + camelTiredness += random.randint(1, 4) + nativesTraveled += random.randint(7, 15) + elif user_choice.upper() == 'B': + traveledMiles += random.randint(5, 13) + print('Miles traveled:', traveledMiles) + thirst += 1 + camelTiredness += 1 + nativesTraveled += random.randint(7, 15) + elif user_choice.upper() == 'A': + if canteenDrinks > 0: + canteenDrinks -= 1 + print('Drinks in canteen:', canteenDrinks) + thirst = 0 + else: + print('Error: no drinks in canteen.') + +if thirst > 4: + print('You are thirsty.') +elif thirst > 6: + print('You died of thirst!') + done = True +if camelTiredness > 5: + print('Your camel is getting tired.') +elif camelTiredness > 8: + print('Your camel is dead.') +if nativesTraveled == 0: + print("You've been caught! Game over, try again.") + done = True +elif nativesTraveled <= -15: + print('The natives are getting close!') +if traveledMiles == 200: + print('You won! Game over, play again!') + done = True diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..2a86fc4 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,108 @@ -# +<<<<<<< HEAD +#Destroy The City Pygame +======= +#Destroy The City PyGame +>>>>>>> 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() +>>>>>>> d65a200f26d213f86446b9aa3fa7733773ae286a diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..13a39e6 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,15 @@ +#!/usr/bin/env python3 +# Chapter 6 Lab Part 1 +# Jessica Lyles +# 11/15/2017 +# Variable for start +start = 10 +# Do 9 times starting at 10 (row) +for i in range(9): + # Loop to print the digits + for j in range(i + 1): + print(start, end=' ') + start += 1 + #print new line + print() \ No newline at end of file diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..176921d 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,24 @@ -# +#!/usr/bin/env python3 +# Chapter 6 Lab Part 2 +# Jessica Lyles +# 11/15/2017 + +# User Input for value of n/how many o's (row wise not column) +userInput = int(input('Please enter a value for n: ')) +# Variable for spaces between +spaces = (userInput*2) - 2 +# Loop to print top line of o's +for i in range(userInput): + print('o'*2, end = '') +# Print new line +print() +# Loop to print o's between +for row in range(1, userInput - 1): + print('o' + (' ' * spaces) + 'o') +# Loop to print bottom line of o's +for j in range(userInput): + print('o'*2, end = '') + + + + diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..76538b7 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,65 @@ -# +""" + 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() + +# -------- 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 + for y in range(0, 500, 20): + for x in range(0, 700, 20): + pygame.draw.rect(screen, GREEN, (x, y, 10, 10)) + + # --- Go ahead and update the screen with what we've drawn. + pygame.display.flip() + + # --- Limit to 60 frames per second + clock.tick(60) + +# Close the window and quit. +pygame.quit() diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..e4644ff 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,77 @@ -# +#!usr/bin/env python3 +# Main_program.py +# Jessica Lyles +# 11/28/2017 + +""" first draft of adventure game """ + +room_list = [] +room = ["You are standing in the entrance of the Mystery House.", None, None, 2, None] +room_list.append(room) + +room = ["You are standing in the Mystery Children's Room.", None, 2, 4, None] +room_list.append(room) + +room = ["You are standing in the hallway of the Mystery house.", 0, 3, 5, 1] +room_list.append(room) + +room = ["You are standing in the Mystery Bathroom.", None, None, None, 2] +room_list.append(room) + +room = ["You are standing in the Mystery Children's Closet.", 1, None, None, None] +room_list.append(room) + +room = ["You are standing in the Mystery Parent's Room.", 2, None, 6, None] +room_list.append(room) + +room = ["You are in the Mystery Parent's Bathroom.", 5, None, None, None] +room_list.append(room) + +current_room = 0 + + +done = False + +while done == False: + print("") + print(room_list[current_room][0]) + + print('Options: North, South, East, or West.') + user_choice = input("Where would you like to go? ") + + if user_choice == "North": + next_room = room_list[current_room][1] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + elif user_choice == "East": + next_room = room_list[current_room][2] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + elif user_choice == "South": + next_room = room_list[current_room][3] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + elif user_choice == "West" : + next_room = room_list[current_room][4] + if next_room == None: + print("You can't go that way.") + else: + current_room = next_room + + else: + print("Program does not understand your choice, please reenter it below.") + + + + + + diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..484071c 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. - + print('Lyles') 2. How do you enter a comment in a program? - + Put a # in front of the comment, and the program will ignore it. 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 line of code prints .666 (the answer to 2 divided by 3), but the 2nd one prints out '1' as it is the closest integer. They give a different answer because '/' indicates division, but '//' indicates floor division. 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. - + pi = 0 5. Why does this code not work? A = 22 print(a) - + The first a is capitalized while the one in the paranthesis is not, and the program will not recognized the lowercase a as defined. 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 - + The best variable name would be the last one, 'Area_Of_Rectangle', as it clearly states what this variable represents and seperates the words and capitalizes them, making it easier to read. 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.) @@ -60,16 +60,16 @@ x2x total% #left - + 'account number', 'account#', 'total%', and '#left' are not allowed in Python. 8. Why does this code not work? print(a) a = 45 - + 'a' has to be defined before it can be printed. 9. Explain the mistake in this code: pi = float(3.14) - + '3.14' is already float, so there is no need to put 'float' in front of it. 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -78,68 +78,68 @@ pi = x area = pi * radius ** 2 print(area) - + There was no need to put in 'x = 3.14' as they could've easily coded 'pi = 3.14' instead of making it 'pi = x'. 11. Explain the mistake in the following code: x = 4 y = 5 a = ((x) * (y)) print(a) - + There is no need for the parentheses around x and y in the 'a' variable. 12. Explain the mistake in the following code: x = 4 y = 5 a = 3(x + y) print(a) - + There is mo '*' so the program does not know multiply the 3 with 'x + y'. 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) - + There needs to be an 'int' before input, as it has to be a number put in. 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 do print the same value, but code line 2 would be better to use as it is easier and quicker to read instead of things either being jumbled up together or spaced really far apart. 15. What is a constant? - + A constant is something that stays the same the entire time, like a fixed variable. 16. How are variable names for constants different than other variable names? - + The fixed variable or constant name is fully capitalized, so it can identified easily. 17. What is a single quote and what is a double quote? Give and label an example of both. - + Single and double quotes are both things of puncuation, a single quote being: 'msg'; and a double quote being: "msg". There is not much of a difference between the two in programming, but it must be used correctly. 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("Hello" + "/n" + "world" + "/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) - + Due to order of operations, it does 5 divided by 3 first, instead of adding everything up and then dividing it by 3. 21. What is an ``operator'' in Python? - + An operator is the symbol used to do a specific function or operation, like divison(/) or addition(+). 22. What does the following program print out? x = 3 x + 1 print(x) - + This prints 3, because 'x + 1' is not set to the variable x, and therefore stays 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")) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..52abf9b 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,39 @@ 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.) - + 101 2. Give an example of a decimal number. - + 5 3. Give an example of a hexadecimal number. - + 5 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. - + 1, 2, 4, and 16. 5. What is a compiler? - + A complier transfers the source code(the users program) into machine code. 6. What is source code? - + A source code is the coding of a program that was put in by the user. 7. What is machine language? (Don't just say binary. That's not correct.) - + A series of instructions(binary or hexadecimal) that the computer responds to directly. 8. What is a first generation language? (Don't just say binary. That's not correct.) - + It is a machine-level programming language that is entered through the computer's front panel switches. 9. What is a second generation language? - + It is a grouping of programming languages with assembly languages, and shows the difference between machine languages and higher-level languages. 10. What is a third generation language? (Explain, don't just give one example.) - + This refers to the high-level programming language, and is a step above the assembly language but a step below the fourth-generation language. 11. What is an interpreter and how does it differ from a compiler? - + An interpreter is a computer program that directly performs instructions in a programming language. The difference is the interpreter does not require it to be previously complied in the machine language. 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 + The #1 most popular program language is Java, with python coming right after that in #2. 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.sitepoint.com/best-programming-language-learn-2015-job-demand-salaries/ + The first 2 languages in the job board are Java and JavaScript. 14. What is the difference between the ``syntax'' and ``semantics'' of a language? - + Syntax refers to the grammar of the language, while semantics deals with the meaning assigned to symbols, characters, and words in the language. 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - + IPhone 5se, something that runs on the hardware is its' Touch ID fingerprint scanner, and something from the software would be Siri. diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..512f30e 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,14 +10,26 @@ print("It is hot outside.") else: print("It is not hot out.") - + temperature = float(input("Temperature: ")) 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(number, 'is negative.') + elif number > 0: + print(number, 'is positive.') + else: + print(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) + number = int(input('Enter a number: ')) + if -10 < number < 10 + 1: + print('Success') + 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -27,7 +39,7 @@ print("Correct!") else: print("Incorrect.") - + The program also prints 'Correct!' when the user puts in a lowercase a. 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. @@ -38,13 +50,13 @@ print("x is positive.") else: print("x is not positive.") - + The first issue that doesn't allow it to run is 'x == 4', this needs to be replaced with 'x = 4' as it '==' doesn't define x as a variable. The 2nd issue is that the program does not allow the user to put in a number, and x is fixed at 4, so there will never be 'x is not positive.' as an outcome. 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") - + The first error I saw what 'if x = 3'. This needs to be 'if x = 3:' and the 2nd issue is that it actually needs to have a double '==' instead of just one equal sign ('if x == 3:'). The 3rd error is that the 3 needs to be in quotes, so that the program will recognize it, and print out the "You entered 3". 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 +64,13 @@ print("Correct!") else print("Incorrect! It is Beaker.") - + The first error is the if statement, the variable 'a' is not defined and needs to be changed to 'answer'. The 2nd and 3rd errors are in the else statement, as it cannot be indented like it is (needs to be aligned with if) and needs ':' next to it. Finally the 4th error is the equal sign in the if statement, it needs to be double ('=='). 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!") - + There is no else statement, so no matter what the user puts into the input statement, it will always print out "That is good to hear!". Also, there needs to be a space between 'today?' and the ending quotation mark for style purposes. 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 +90,11 @@ print("Fizz") if z: print("Buzz") - + Guess: I do not think the coding will initally work because of the 'y = x == 6' and 'z = x == 5'. + Answer: It prints out '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) @@ -96,7 +112,19 @@ print(x == 5 and y == 10) print(x == 5 and y == 5) print(x == 5 or y == 5) - + Guess: I think it will print out '5'. + Answer: It prints out '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) @@ -109,7 +137,26 @@ print( (2 == 2) == "True" ) print( (2 == 2) == True ) print(3 < "3") - + Guess: I think it will print 'True + False + True + True + True + True + True + False' + Answer: It printed out 'True + False + True + True + True + False + False + True + Traceback (most recent call last): + File "/home/jlyles/TestingProgram.py", line 9 in + print(3 < "3") + TyperError: unorderable types: int() < str()' 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -129,7 +176,7 @@ money = 70 else if user_input = C: money = 50 - +The first thing I noticed before I did anything was the use of 'else if', instead of this the programmer needs to use 'elif'. Another error I noticed was the '=' in the first if statement, this again needs to be '=='. The same goes with the 'elif' statements. When I first tried to run the program, it told me that 'A' was not defined, and I assume it goes the same for the other answers, so the programmer needs to define the letters as their answers, so the program can run. (Also space between '?' and end quote) At the end whenever the program prints nothing, and does not tell the user how much money they receive due to their occupation, so the programmer must add that if they want the user to be able to see their amount of money. diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..f4f9024 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,17 +13,36 @@ 1. Write a Python program that will use a for loop to print your name 10 times, and then the word ``Done'' at the end. + + for i in range(10): + print('Lyles') + 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') + print('Gold') 3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive. + + for i in range(2, 100 + 1, 2): + print(i) 4. Write a Python program that will use a while loop to count from 10 down to, and including, 0. Then print the words ``Blast off!'' Remember, use a WHILE loop, don't use a FOR loop. + + countdown = 10 + while countdown >= 0: + print(countdown) + countdown = countdown - 1 + print('Blast Off!') + 5. There are three things wrong with this program. List each. (3 pts) @@ -35,11 +54,17 @@ total = total + i print("The total is:", x) + The first problem is that the program prints out the last input instead of adding them all together and printing the total, so to fix this you must replace the 'x' at the end to 'total'. The 2nd issue is the 'total = total + i' line of code. To fix this, you must replace 'i' with 'x', as we are adding the inputs, not indexes. The 3rd issue is that we need to add 'int' in front of 'input("Enter a number: ")' as the user needs to put in a number/integer, not a word. I also found out instead of changing the previous error and changing 'total = total + x' to 'total = total + int(x)' works as well. + 6. Write a program that prints a random integer from 1 to 10 (inclusive). 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 + number = random.randrange(1, 11) + print(number) 8. Write a Python program that will: (3 pts) @@ -49,6 +74,24 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. + totalSum = 0 + positives = 0 + negatives = 0 + zeros = 0 + for i in range(7): + x = int(input('Enter a number: ')) + totalSum = totalSum + x + if x > 0: + positives = positives + 1 + elif x < 0: + negatives = negatives + 1 + else: + zeros = zeros + 1 + print('The sum is:', totalSum) + print('Number of positives:', positives) + print('Number of negatives:', negatives) + print('Number of zeros:', zeros) + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +100,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 + numberHeads = 0 + numberTails = 0 + for i in range(50): + number = random.randrange(0, 2) + if number == 1: + numberHeads += 1 + print('Heads') + elif number == 0: + numberTails += 1 + print('Tails') + print('Heads:', numberHeads) + print('Tails:', numberTails) + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -66,4 +123,48 @@ * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. - + print('Rock, Paper, or Scissors? ') +print('O is for "Rock."') +print('1 is for "Paper."') +print('2 is for "Scissors."') +usersPick = input('Your choice: ') +import random +for i in range(1): + number = random.randrange(0, 3) + if usersPick == '0': + print('Rock!') + elif usersPick == '1': + print('Paper!') + elif usersPick == '2': + print('Scissors!') +for i in range(1): + number = random.randrange(0, 3) + if number == 0: + print("Robot's Choice: Rock!") + elif number == 1: + print("Robot's Choice: Paper!") + elif number == 2: + print("Robot's Choice: Scissors!") +if usersPick == '0': + if number == 0: + print("It's a tie, try again!") + elif number == 1: + print('Robot wins!') + elif number == 2: + print('You win!') +if usersPick == '1': + if number == 0: + print('You win!') + elif number == 1: + print("It's a tie, try again!") + elif number == 2: + print('Robot wins!') +if usersPick == '2': + if number == 0: + print('Robot wins!') + elif number == 1: + print('You win!') + elif number == 2: + print("It's a tie, try again!") + + diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..2010ba2 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -7,21 +7,35 @@ 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) @@ -32,38 +46,59 @@ * What does [100, 100] do? * What does 5 do? + The 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? * What is the length and the width of the ellipse? - 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) + The coordinates are [50, 100], [0, 200], [200, 200] and [100, 50]. This polygon has four sides/angles/points which explains why there are 4 different sets of coordinates. + 16. What does pygame.display.flip() do? + + This updates and shows on the screen what the user has drawn. 17. What does pygame.quit() do? - + + pygame.quit() closes the window and quits the game. + 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(DISPLAYSURF, BLUE, (300, 50), 20, 0) + + diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..2a6397c 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,8 @@ while x < 10: print(x) x = x + 2 + Guess: Prints out 0, 2, 4, 6, and 8 on seperate lines. + Answer: Prints out 0, 2, 4, 6, and 8 on seperate lines. 2. What does this program print out? @@ -24,6 +26,8 @@ while x < 64: print(x) x = x * 2 + Guess: Prints out 1, 2, 4, 8, 16, and 32 on seperate lines. + Answer: Prints out 1, 2, 4, 8, 16, and 32 on seperate lines. 3. Why is the and x >= 0 not needed? @@ -31,6 +35,7 @@ while x < 10 and x >= 0: print(x) x = x + 2 + It does not need to be checked because x is set to start at 0, and there is no chance of it ever going down in value. 4. What does this program print out? (0 pts) Explain. (1 pt) @@ -40,6 +45,7 @@ if x == "1": print("Blast off!") x = x - 1 + This program prints out 5, 4, 3, 2, and 1 on seperate lines. This prints only that out because an integer can never equal a string, because the programmer put quotations around 1, it will never be equal to that and will then never print out "Blast off!". 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) @@ -48,6 +54,8 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") + + To fix this error of looping forever you must set the print statement under the while loop to x, as previously it was only taking the first number that you had entered as x, and couldn't change it. The other thing you must add to make this program work is simply replace the x in the while loop with int(x). 6. Fix the following code: @@ -59,6 +67,8 @@ print("Blast-off") + To fix this code you have to switch the '<' to a '>' as before this switch this is telling the program that if x is less than 0, then do the loop. Because x is set to 10, this will never happen and it will only print out "Blast-off." The only other thing to fix about the program coding is to set x to x - 1 (aka x = x - 1) 'x -1' does nothing. + 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) @@ -66,6 +76,8 @@ for i in range(10): print(i) i += 1 + + The first thing that I noticed that the coding did not need was the 'i = 10.' This is because the loop already has a range of what i is, so the coder does not need to set it beforehand. The other piece of coding not needed for this program to run would be 'i += 1' as the range works as a stepper do basically do this already, with the help of the print statement as well to show the numbers. 8. Explain why the values printed for x are so different. (2 pts) @@ -85,4 +97,5 @@ x += 1 print(x) + The 1st sample prints out '20' while the 2nd one prints out '110'. The difference between the two codings are how the for loops are set up, the first being seperate and the second being nested. The first one does each loop seperately and only does j when i is finished, but the second one does j while i is still functioning. The first is only doing i 10 times and j 10 times, but the second one is doing j 10 times for each time i is done, so bascially 100 times, plus the 10 that i does. diff --git a/Worksheets/worksheet_07.txt b/Worksheets/worksheet_07.txt index a87ff3f..b4e7776 100644 --- a/Worksheets/worksheet_07.txt +++ b/Worksheets/worksheet_07.txt @@ -8,7 +8,9 @@ 1. List the four types of data we've covered, and give an example of each: - + + The first type of data is a string, something like "Hello, World." The second type is an integer, a number, and an example is "user_input = int(user_input)". The third type is a floating point, which is also a number but includes the numbers past the point, an example would be "3.194", and finally we have the boolean, true or false, and an example is "while done is 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,11 +21,15 @@ print(my_list[4]) print(my_list[5]) + This program prints out 2, 101, and an error message as there is no 5th variable in the list. + 3. What does this code print out? my_list=[5, 2, 6, 8, 101] for my_item in my_list: print(my_item) + + The program prints out 5, 2, 6, 8, and 101. 4. What does this code print out? @@ -34,6 +40,8 @@ my_list2[2] = 10 print(my_list2) + It prints out [5, 2, 6, 10, 101] and an error message because in the list the 3rd variable (8) is changed to 10 before it prints the list and the error message is to tell you you can't change the variables in a tuple like a list. + 5. What does this code print out? my_list = [3 * 5] @@ -41,6 +49,8 @@ my_list = [3] * 5 print(my_list) + This code prints out [15] and [3, 3, 3, 3, 3] as the first list does 3 times 5, but the 2nd '3' 5 times. + 6. What does this code print out? my_list = [5] @@ -48,6 +58,8 @@ my_list.append(i) print(my_list) + This prints out [5, 0, 1, 2, 3, 4] as the list starts at the variable 5, then goes up in range to 5. + 7. What does this code print out? print(len("Hi")) @@ -56,17 +68,23 @@ print(len("2")) print(len(2)) + The code prints out 2, 9, 8, 1, and an error message as 2 is an integer and does not have a len function. The other numbers represent how many letters, spaces, characters, etc. are in the strings. + 8. What does this code print out? print("Simpson" + "College") print("Simpson" + "College"[1]) print( ("Simpson" + "College")[1] ) + This prints out 'SimpsonCollege", "Simpsono" and "i" (without qoutations) as in the first there is no space between them indicated, the second prints Simpson and the 1st variable of college, and the 3rd only prints the 1st variable of the entire string. + 9. What does this code print out? word = "Simpson" for letter in word: print(letter) + + This prints out S, i, m, p, s, o, and n on all different lines because the for loop steps through the entire word, previously defined as "Simpson" and prints out each letter/variable in it. 10. What does this code print out? @@ -75,17 +93,23 @@ word += "College" print(word) + This prints out "SimponCollegeCollegeCollege" because there are no indicated spaces, word is defined originally as "Simpson" and then "College" is added 3 times in the range. + 11. What does this code print out? word = "Hi" * 3 print(word) + This prints out "HiHiHi" as word is defined as the string "Hi" times 3 and then prints the word. + 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]) + This code prints out "The 3rd sopt is: " and "The -1 spot is: ." as the 3rd variable is a space, and the -1 variable is the period at the end of the line. + 13. What does this code print out? s = "0123456789" @@ -93,9 +117,17 @@ print(s[:3]) print(s[3:]) + This prints out 1, 012, and 3456789 because the 1st variable is 1, the 2nd print statement starts at 1 and stops before 3, and the 3rd print statement starts at variable three and goes to the end of the string. + 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 = [] + numbers = input('Enter 5 Numbers: ') + for item in numbers: + numberList.append(int(item)) + 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 @@ -105,4 +137,10 @@ my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] + my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] + list_average = 0 + for i in range(len(my_list)): + list_average = list_average + int(my_list[i]) + print((list_average)/len(my_list)) +