diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..0f6bd83 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,8 @@ -# +#!/usr/bin/env python3 +# 1.1 Lab Part A +# Bethany DuMontelle +#1 November 2017 + +fahrenheit_temp = int(input('Enter temperature in Fahrenheit: ')) +celsius_temp = ( ((fahrenheit_temp) - 32) / 1.8 ) +print(celsius_temp) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..c368c66 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 B Chapter 1 +#Bethany DuMontelle +#1 November 2017 + +print('Area of a trapezoid') +trap_height = int(input("Enter the height of the trapezoid: ")) +trap_bbase = int(input('Enter the ength of the bottom base: ')) +trap_tbase = int(input('Enter the length of the top base: ')) + +trap_area = 1/2 * (( (trap_bbase) + (trap_tbase) ) * (trap_height)) + +print(str(trap_area)) \ No newline at end of file diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..ce6578f 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,14 @@ -# +#!/usr/bin/env python3 +#Chapter 1 Lab Part C +#Bethany DuMontelle +#2 November 2017 + +PI = int(3.141592654) + +print('Area of a circle') + +circle_radius = int(input('What is the radius of the circle? ')) + +circle_area = ( (PI) * (circle_radius) ** 2 ) + +print(circle_area) \ No newline at end of file diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..ec633a4 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,83 @@ -# +#!/usr/bin/env python3 +#Chapter 3 quiz +#Bethany DuMontelle +#3 November 2017 + +print('Time for a quiz! Are you ready?') +print() + +#Sets up score +score = int(0) + +#q1 +question_one = int(input('How many pokemon are there as of \ +2017, not including other forms? ')) + +if question_one == 802: + score = score + 1 + print('Correct!') +else: + print('Incorrect! There are currently 802 pokemon.') +print() + +#q2 +print("What does pikachu's shiny look like?") +print('A. Blue') +print('B. Light yellow') +print('C. Dark yellow') +question_two = input() +if question_two.lower() == 'c': + score = score + 1 + print('Correct!') +else: + print('Incorrect! Pikachu is dark yellow when shiny.') +print() + +#q3 +print('Which of these pokemon are considered to have the worst shiny of \ +all time?') +print('A. Pikachu') +print('B. Garchomp') +print('C. Charizard') +question_three = input() +if question_three.lower() == 'b': + score = score + 1 + print('Correct!') +else: + print('Incorrect! Garchomp is thought to have the worst shiny ever.') +print() + +#q4 +print('As of generation 6, what are the odds of finding a shiny pokemon? ') +question_four = int(input('1 in ')) +if question_four == 4096: + score = score + 1 + print('Correct!') +elif question_four == 8192: + print('Wrong generation! It is now 1 in 4096.') +else: + print('Incorrect! The odds are 1 in 4096.') +print() + +#q5 +print('True or false: pokemon can change their shinies when mega-evolved.') +question_five = input() +if question_five.lower() == 'true': + score = score + 1 + print('Correct!') +else: + print('Incorrect! Some do change their shinies when mega-evolved.') +print() + +#results +percent = (int(score) / 5) * 100 +print('Your total score is', str(score) + ' out of 5.') +print('This is also ' + str(percent) + ' percent.') +if score == 0 or score == 1: + print('You didn\'t do very well.') +elif score == 2 or score == 3: + print('Not very good, but not that bad either.') +elif score == 4: + print('Pretty good!') +else: + print('You did fantastic!') \ No newline at end of file diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..a62b403 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,138 @@ -# +#!/usr/bin/env python3 +#Lab 4 chapter 4 Camel +#Bethany DuMontelle +#3 November 2017 + +from random import randint + +#sets up the variables needed +miles_left = 0 +natives_range = -20 +user_thirst = 0 +canteen = 3 +camel_rest = 0 +done = False + +#Introduces the player +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') +print('your desert trek and out run the natives.') + +#begins the loop +while done != True: + #tells the player how close they are, stops negative numbers from showing + native_close = (miles_left) - (natives_range) + + #sets up if an oasis can be found every time the loop starts over + oasis = randint(1,15) + + #tells the player important information + print('You have traveled', str(miles_left), 'miles.') + + if native_close < 15: + print('The natives getting close!') + else: + print('The Natives are', str(native_close), 'miles away from you.') + + print('You have', str(canteen), 'drinks left in your canteen.') + + if user_thirst >= 4: + print('You are thirsty!') + + if camel_rest >= 5: + print('The camel is getting tired!') + + + print('What would you like to do?') + 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() + + #allows the player to drink from their canteen + #also prevents players from drinking water they don't have + if user_choice.lower() == 'a': + if canteen <= 0: + print('You don\'t have any more water!') + else: + user_thirst = user_thirst - 1 + canteen = canteen - 1 + + #moves the player, also can find an oasis if the random number was 1 + elif user_choice.lower() == 'b': + miles_move = randint(5,12) + miles_left = (miles_left) + (miles_move) + natives_move = randint(7,14) + natives_range = (natives_range) + (natives_move) + camel_rest = (camel_rest) + 1 + user_thirst = user_thirst + 1 + print('You moved', + (miles_move), 'miles.') + if oasis == 1: + canteen_fill = randint(2,5) + canteen = (canteen) + (canteen_fill) + user_thirst = user_thirst + 2 + print('You found an oasis!') + print('You can now drink', (canteen_fill), 'more times.') + + #also moves the player, but with more random elements and an oasis can + #be found as well + elif user_choice.lower() == 'c': + miles_move = randint(10,20) + miles_left = (miles_left) + (miles_move) + natives_move = randint(7,14) + natives_range = (natives_range) + (natives_move) + camel_tired = randint(1,3) + camel_rest = (camel_rest) + (camel_tired) + user_thirst = user_thirst + 1 + print('You moved', + (miles_move), 'miles.') + if oasis == 1: + canteen_fill = randint(2,5) + canteen = (canteen) + (canteen_fill) + user_thirst = user_thirst + 2 + print('You found an oasis!') + print('You can now drink', (canteen_fill), 'more times.') + + #sets camel_rest to 0, moves the natives up as well + elif user_choice.lower() == 'd': + camel_rest = 0 + natives_move = randint(7,14) + natives_range = (natives_range) + (natives_move) + print('The camel is happy.') + + #gives the player more stats + elif user_choice.lower() == 'e': + print('Miles left:', 200 - (miles_left)) + print('Native distance:', (native_close)) + print('Canteen drinks:', str(canteen)) + print('Days until water is needed:', 6 - (user_thirst)) + print('Camel tiredness:', (camel_rest), 'out of 8') + + #ends the game + elif user_choice.lower() == 'q': + print('You gave up. Your family is disappointed in you.') + done = True + + #winning conditon + if miles_left >= 200: + print('You made it across the Mobi desert! Congradulations!') + done = True + + #way to lose + if user_thirst >= 6: + print('You died of thirst! Game over!') + done = True + + #another way to lose + if camel_rest >= 8: + print('Your camel died! Game over!') + done = True + + #yet another way to lose + if natives_range >= miles_left: + print('The Natives got you! Game over!') + done = True \ No newline at end of file diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..fa36982 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,76 @@ -# +#!/usr/bin/env python3 +#Lab 5 Draw a Picture +#Bethany DuMontelle +#8 November 2017 + +#Starts up pygame +import pygame +pygame.init() + +#Establishes colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +LIGHT_GREEN = (74, 224, 129) +LIGHT_BLUE = (52, 198, 247) +DEEP_PURPLE = (79,18,201) +SKY = (235, 193, 96) +SUN_YELLOW = (246, 255, 0) +SUN_RING = (219, 222, 95) +PANK = (235, 103, 226) +RED = (224, 13, 52) + +size = (800, 800) +screen = pygame.display.set_mode(size) + +done = False +while not done: + + #changes background color + screen.fill(SKY) + + #Makes the ocean + pygame.draw.rect(screen, LIGHT_BLUE, [0, 350, 800, 800], 0) + + #Creates ring around the sun + pygame.draw.circle(screen, SUN_RING, [10, 10], 140, 0) + + #Creates the sun + pygame.draw.circle(screen, SUN_YELLOW, [10, 10], 100, 0) + + #octopus legs + pygame.draw.line(screen, DEEP_PURPLE, [300, 350], [125, 500], 40) + pygame.draw.line(screen, DEEP_PURPLE, [300, 380], [220, 600], 40) + pygame.draw.line(screen, DEEP_PURPLE, [340, 380], [300, 620], 40) + pygame.draw.line(screen, DEEP_PURPLE, [380, 380], [360, 590], 40) + pygame.draw.line(screen, DEEP_PURPLE, [420, 380], [420, 625], 40) + pygame.draw.line(screen, DEEP_PURPLE, [460, 380], [480, 595], 40) + pygame.draw.line(screen, DEEP_PURPLE, [500, 380], [550, 585], 40) + pygame.draw.line(screen, DEEP_PURPLE, [510, 350], [630, 570], 40) + + #octopus body + pygame.draw.ellipse(screen, DEEP_PURPLE, [275, 200, 250, 275], 0) + + #octopus eyes + pygame.draw.ellipse(screen, WHITE, [335, 300, 35, 35], 0) + pygame.draw.ellipse(screen, BLACK, [340, 310 , 25, 25], 0) + pygame.draw.ellipse(screen, WHITE, [435, 300, 35, 35], 0) + pygame.draw.ellipse(screen, BLACK, [440, 310 , 25, 25], 0) + + #octopus mouth + pygame.draw.polygon(screen, PANK, [[400, 420], [440, 360], [360, 360]], 0) + pygame.draw.polygon(screen, RED, [[400, 412], [420, 380], [380, 380]], 0) + + #Seaweed + x_offset = 20 + while x_offset < 780: + pygame.draw.line(screen, LIGHT_GREEN, [20 + x_offset, 600],\ + [20 + x_offset, 800], 15) + x_offset = x_offset + 40 + + #updates the screen to show the picture + pygame.display.update() + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True +pygame.quit() \ No newline at end of file diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..c83aef5 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,18 @@ +#!/usr/bin/env python3 +#Lab Part 1 +#Bethany DuMontelle +#15 November 2017 +#Establish starting number +start = 10 + +#loops it 9 times +for numbers in range(9): + +#adds 1 plus the range when it does down + for down in range(numbers + 1): + print( start , end = ' ') + start += 1 + +#new print statement at the end + 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..c44cdbc 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,21 @@ -# +#!/usr/bin/env python3 +#Lab Part 2 +#Bethany DuMontelle +#15 November 2017 + +#ask user for number of zeros +number = int(input('How many o\'s? ')) + +#spaces used later +spaces = (number * 2) - 2 + +#print zeros times number times 2 +print('o' * ((number) * 2)) + +#loop the number of times the user asked - 2 with o's, add the spaces from +#earlier, then add another o +for o1 in range(1, number - 1): + print('o' + (' ' * spaces) + 'o') + +#repeat zeros on bottom +print('o' * ((number) * 2)) \ No newline at end of file diff --git a/Lab 06 - Loopy Lab/part_3.py b/Lab 06 - Loopy Lab/part_3.py index 792d600..ce022c1 100644 --- a/Lab 06 - Loopy Lab/part_3.py +++ b/Lab 06 - Loopy Lab/part_3.py @@ -1 +1,6 @@ -# +#!/usr/bin/env python3 +#Lab Part 3 +#Bethany DuMontelle +#15 November 2017 + +#We don't have to do this but I almost started on it so that's why this is here \ No newline at end of file diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..347ccb2 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,37 @@ -# +#!/usr/bin/env python3 +#Lab Part 4 +#Bethany DuMontelle +#17 November 2017 + +#start pygame +import pygame +pygame.init() + +#Set up and open up the screen +size = (800, 800) +screen = pygame.display.set_mode(size) + +#set the colors for the pattern +LIGHT_BLUE = (52, 198, 247) + +#starts the exit option +done = False +while not done: + +#loop it across the screen + y_offset = -4 + for x in range(1, 100): + y_offset = y_offset + 10 + x_offset = 6 + for y in range(1, 100): + pygame.draw.circle(screen, LIGHT_BLUE, [x_offset, y_offset], 3, 0) + x_offset = x_offset + 10 + +#screen updates + pygame.display.update() + +#exit + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True +pygame.quit() \ No newline at end of file diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..563969d 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,97 @@ -# +#!/usr/bin/env python3 +#Chapter 7 Lab +#Bethany DuMontelle +#November 20 2017 + +"""Just a program that lets you go into a variety of rooms""" + +#creates the room list +room_list = [] + +#establishes all the room descriptions and the direction numbers +#note: the number direction order is: north, east, south, west +#the layout is in my notebook on page 37 +bedroom = ['You\'re in the bedroom. There\'s nothing of interest in here. \ +You can either go \nnorth into the party room or in the \ +dining room east.', 4, 1, None, None] + +dinning_room = ['This is the dinning room. There\'s a table in here neatly \ +set up. You can go to the bedroom\nwest, the kitchen north, \ +and the basement east.', 5, 2, None, 0] + +basement = ['You are in the basement. It is very spooky down here.\ +You can\'t see anything. You can\nonly go back west \ +to the dining room.', None, None, None, 1] + +balcony = ['You\'re on the balcony. It\'s little chilly out today. You \ +can only go back\ninto the party room east.', None, 4, None, None] + +party_room = ['It\'s the party room! There is a disco ball on the ceiling and \ +a dance floor. Other than\nthat, nothing else is here. You can go west to the \ +balcony, north to the\nattic, east to the kitchen, and south to the \ +bedroom.', 6, 5, 0, 3] + +kitchen = ['This is the kitchen. The wall is covered in knives. Seems safe e\ +nough.\nYou can go west to the party room or south to the dining r\ +oom.', None, None, 1, 4] + +attic = ['You\'re in the attic. Wow! Look at all the dust. You could make a \ +small garden with all the\ndust in here. You may want to leave before the dus\ +t is a mild inconvenience.\nYou can only go south, back to the p\ +arty room.', None, None, 4, None] + +#appends it all to the room_list +room_list.append(bedroom) +room_list.append(dinning_room) +room_list.append(basement) +room_list.append(balcony) +room_list.append(party_room) +room_list.append(kitchen) +room_list.append(attic) + +#whatever room you are in +current_room = 0 + +#sets up the loop +done = False + +#starts the game loop +while done == False: + print() + print(room_list[current_room][0]) + direction = str(input('Where would you like to go now? ')) + + #all the directions possible to go, the else statement stops impossible + #movement for each direction + if direction.lower() == 'n' or direction.lower() == 'north': + if room_list[current_room][1] != None: + current_room = room_list[current_room][1] + else: + print('You can\'t go that way!') + + elif direction.lower() == 'e' or direction.lower() == 'east': + if room_list[current_room][2] != None: + current_room = room_list[current_room][2] + else: + print('You can\'t go that way!') + + elif direction.lower() == 's' or direction.lower() == 'south': + if room_list[current_room][3] != None: + current_room = room_list[current_room][3] + else: + print('You can\'t go that way!') + + elif direction.lower() == 'w' or direction.lower() == 'west': + if room_list[current_room][4] != None: + current_room = room_list[current_room][4] + else: + print('You can\'t go that way!') + + #ends the game + elif direction.lower() == 'quit': + print('Okay.') + done = True + + #If the statement doesn't equal any of the above words this will print + else: + print('I don\'t understand.') \ No newline at end of file diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..88fc780 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,22 +6,27 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. + print(Bethany DuMontelle) 2. How do you enter a comment in a program? + Use a # 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 prints 0.6666666666666666, while the other code prints 0. This is because the first code is division, while the other one is floor division. 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. + pi = 3.141592654 5. Why does this code not work? A = 22 print(a) + It tries to print out a lowercase a, which is different from an uppercase A. 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -34,6 +39,8 @@ area_of_rectangle Area_Of_Rectangle + area_of_rectange is the best name to use. + 7. Which of these variables names are not allowed in Python? (More than one might be wrong. Also, this question is not asking about improper names, just names that aren't allowed. Test them if you aren't sure.) @@ -61,15 +68,21 @@ total% #left + account number, 1Apple, 2x, and #left are not allowed. + 8. Why does this code not work? print(a) a = 45 + a needs to be established before it is printed. + 9. Explain the mistake in this code: pi = float(3.14) + float is used for floating point numbers, int needs to be used for integers. + 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -79,6 +92,8 @@ area = pi * radius ** 2 print(area) + The variables should be more specific. + 11. Explain the mistake in the following code: x = 4 @@ -86,6 +101,8 @@ a = ((x) * (y)) print(a) + x and y need to be integers with int. + 12. Explain the mistake in the following code: x = 4 @@ -93,53 +110,77 @@ a = 3(x + y) print(a) + int is needed. + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) + float needs to be before input, not the other way around. + 14. Do all these print the same value? Which one is better to use and why? print(2/3+4) print(2 / 3 + 4) print( 2 / 3+ 4 ) + The 2nd one is the best because it looks nice than the 1st and 3rd one, and is more accepted to do it that way. + 15. What is a constant? + + A variable that does not change. 16. How are variable names for constants different than other variable names? + + The variable name needs to be in all caps. 17. What is a single quote and what is a double quote? Give and label an example of both. + + 'Single quote' + "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.) - + + "Here is a sentence with a /" in it." + 19. Can a Python program print text to the screen using single quotes instead of double quotes? + Of course + 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) + The program tries to divide 5 by 3, then add everything together. + 21. What is an ``operator'' in Python? + A symbol that makes the program do a mathmatical equation. + 22. What does the following program print out? x = 3 x + 1 print(x) + The program prints out 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")) + print(value) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..7239ecd 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -7,36 +7,67 @@ binary, decimal, and hexadecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.) + 1011 0001 1101 + 2. Give an example of a decimal number. + + 56 3. Give an example of a hexadecimal number. + + F7C6 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. + + 1, 2, 4, 8, 16 5. What is a compiler? + Takes the program written and converts it to machine code. + 6. What is source code? + + The code that is typed by a user. 7. What is machine language? (Don't just say binary. That's not correct.) + + Machine language uses the same system as binary code does, and can not only use it to interpret commands, but also to store data, like documents. 8. What is a first generation language? (Don't just say binary. That's not correct.) + + A first generation language is where a number represents data or instructions for a computer to perform. 9. What is a second generation language? + + Assembly language 10. What is a third generation language? (Explain, don't just give one example.) + + Program languages that uses logic to make certain commands perform, such as python, COBOL, and C#. 11. What is an interpreter and how does it differ from a compiler? + + An interpreter directly translates source code into machine code, while a compiler takes it and turns it into machine code. 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. + The most common languages people are looking for when hiring are python, c+, and java. + https://stackoverflow.com/jobs + 14. What is the difference between the ``syntax'' and ``semantics'' of a language? + Syntax is the code structure, while semantics is the meaning of the symbols and words. + 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - + A piece of technology I commonly use is my new 3ds. It has duel screens, with the bottom screen being a touch-screen. The top screen is able to go in 3d, thus the name. + It also connects to the intenet and you can download games from their shop in the console. diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..ef193fa 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,13 +10,27 @@ print("It is hot outside.") else: print("It is not hot out.") + + quotes need to go around 90. 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. + + user_number = int(input('Enter a number: ')) + if user_number == '0': + print('Your number is 0.') + elif user_number < '0': + print('Your number is negative.') + else: + print('Your number is positive.') 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) + + user_number = int(input('Enter a number: ')) + if user_number >= -10 and user_number <= 10: + print('Success') 4. This runs, but there is something wrong. What is it? (1 pt) @@ -27,6 +41,8 @@ print("Correct!") else: print("Incorrect.") + + The print statements need to be before the user input, or else they won't know their choices. 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. @@ -38,12 +54,16 @@ print("x is positive.") else: print("x is not positive.") + + 0 should not be included, as it is not positive or negative. The other issue is that there should only be one = when defining x as 4. 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 if statement needs to have 2 = signs for it to work, a : is needed after the if statement, and the print statement does not work. 7. There are four things wrong with this code. Identify all four issues. (4 pts) @@ -52,12 +72,16 @@ print("Correct!") else print("Incorrect! It is Beaker.") + + else should not be indented and needs a :, a needs to be answer or answer needs to be a, and there needs to be 2 = instead of one. 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!") + + x needs to be defined as equal to Glad(x == "Happy" or 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. @@ -78,6 +102,9 @@ print("Fizz") if z: print("Buzz") + + My guess: Fizz + Actual output: 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 +124,9 @@ print(x == 5 and y == 5) print(x == 5 or y == 5) + My guess: true, false, true, false, false, true, false, true, false, true + Actual output: true, false, true, flase, flase, true, false, true, false, true + 11. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts) @@ -110,6 +140,9 @@ print( (2 == 2) == True ) print(3 < "3") + My guess: true, false, true, true, true, true, false, true, false + Actual output: true, false, true, true, true, flase, false, true, int str error + 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -129,6 +162,8 @@ money = 70 else if user_input = C: money = 50 + + there should be 2 = signs and A, B, and C should be in quotes. diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..83fa556 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,17 +13,34 @@ 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. + + user_name = input('Enter your name: ') + for i in range(10): + print(user_name) 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(10): + 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, 101): + 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 != -1: + print(countdown) + countdown = countdown - 1 + print('Blastoff!') 5. There are three things wrong with this program. List each. (3 pts) @@ -35,11 +52,19 @@ total = total + i print("The total is:", x) + x in print needs to be str, the user input should be before the loop, and there is no way to end the loop while it's running. + 6. Write a program that prints a random integer from 1 to 10 (inclusive). + from random import randint +print(randint(1,10)) + 7. Write a program that prints a random floating point number somewhere between 1 and 10 (inclusive). Do not make the mistake of generating a random number from 0 to 10 instead of 1 to 10. + +for i in range(0,11): + print(float(i)) 8. Write a Python program that will: (3 pts) @@ -49,6 +74,73 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. + num_1 = int(input('Print a number: ')) +num_2 = int(input('Print a number: ')) +num_3 = int(input('Print a number: ')) +num_4 = int(input('Print a number: ')) +num_5 = int(input('Print a number: ')) +num_6 = int(input('Print a number: ')) +num_7 = int(input('Print a number: ')) + +zero = 0 +negative = 0 +positive = 0 + +print( (num_1) + (num_2) + (num_3) + (num_4) + (num_5) + (num_6) + (num_7) ) + +if num_1 < 0: + negative = negative + 1 +elif num_1 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +if num_2 < 0: + negative = negative + 1 +elif num_2 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +if num_3 < 0: + negative = negative + 1 +elif num_3 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +if num_4 < 0: + negative = negative + 1 +elif num_4 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +if num_5 < 0: + negative = negative + 1 +elif num_5 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +if num_6 < 0: + negative = negative + 1 +elif num_6 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +if num_7 < 0: + negative = negative + 1 +elif num_7 > 0: + positive = positive + 1 +else: + zero = zero + 1 + +print('Zero: ' + str(zero)) +print('Positive: ' + str(positive)) +print('Negative: ' + str(negative)) + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +149,13 @@ * 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. + from random import randint +random_number = (randint(0,1)) +if random_number == 0: + print('Heads') +else: + print('Tails') + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -66,4 +165,24 @@ * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. + from random import randint +opponent_number = (randint(0,2)) + +player = input('Rock, Paper, or Scissors? ') + +if player.lower() == 'rock': + player_number = 0 +elif player.lower() == 'paper': + player_number = 1 +elif player.lower() == 'scissors': + player_number = 2 + +if player_number == 0 and opponent_number == 1 or player_number == 1 and\ +opponent_number == 2 or player_number == 2 and opponent_number == 0: + print('You lost!') +elif player_number == 0 and opponent_number == 2 or player_number == 1 and\ +opponent_number == 0 or player_number == 2 and opponent_number == 1: + print('You won!') +else: + print('Tie!') diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..58012e1 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -8,20 +8,34 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + The main differences are that that the y coordinates are reversed and focuses on the lower right quadrant rather than 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? + pygame needs to be imported and the screen size needs to be established before the display is set. + 3. Explain how WHITE = (255, 255, 255) represents a color. + It displays green, red, and blue at full intensity, which makes white. + 4. When do we use variable names for colors in all upper-case, and when do we use variable names for colors in all lower-case? (This applies to all variables, not just colors.) + + Upper case is used for variables that will never change, such as a color. 5. What does the pygame.display.set_mode() function do? + + This opens up a new window. 6. What does this for event in pygame.event.get() loop do? + + This makes it so it will take user input. 7. What is pygame.time.Clock used for? + + This is how fast the screen updates. 8. For this line of code: (3 pts) @@ -32,10 +46,18 @@ * What does [100, 100] do? * What does 5 do? +It tells where to draw the line +0,0 is the starting point +100,100 is the ending point +5 is the width of the line in pixels 9. What is the best way to repeat something over and over in a drawing? + + use a loop 10. When drawing a rectangle, what happens if the specified line width is zero? + +The polygon will be filled. 11. Describe the ellipse drawn in the code below. * What is the x, y of the origin coordinate? @@ -45,25 +67,43 @@ pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) + 20, 20 + The origin is the center of the circle, where there is nothing drawn. + the length is 250, width is 100. + 12. When drawing an arc, what additional information is needed over drawing an ellipse? + + It needs to know what the radians is for the angle of the arc. 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + It needs to know what text to write, information about the text(color, size, font, etc), and where is place the text on the screen. + 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 is because one the text information is established, there's no need to keep telling it what the text should be when it already had the information before the loop started. 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 where each point of the polygon is located on the screen, and 5 is the width of each line drawn. + 16. What does pygame.display.flip() do? + + This updates the screen with what was drawn. 17. What does pygame.quit() do? + + This closes the window and stops the program. 18. Look up on-line how the pygame.draw.circle works. Get it working and paste a working sample here. I only need the one line of code that draws the circle, but make sure it is working by trying it out in a full working program. + pygame.draw.circle(screen, WHITE, (200, 200), 20, 5) + diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..50f5a19 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -18,12 +18,18 @@ print(x) x = x + 2 + guess: 0, 2, 4, 6, 8(on separate lines) + actual: 0, 2, 4, 6 ,8(on separate lines) + 2. What does this program print out? x = 1 while x < 64: print(x) x = x * 2 + + guess: 1, 2, 4, 8, 16, 32(separate lines) + actual: 1, 2, 4, 8, 16, 32(separate lines) 3. Why is the and x >= 0 not needed? @@ -32,6 +38,8 @@ print(x) x = x + 2 + x is already 0 and will never decrease, never making the statement true. + 4. What does this program print out? (0 pts) Explain. (1 pt) x = 5 @@ -40,6 +48,8 @@ if x == "1": print("Blast off!") x = x - 1 + + The program prints out 5, 4, 3, 2, 1, and 0 on separate lines because 1 in in quotes, making 1 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,11 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") + x = float(input("Enter a number greater than zero: ")) + + while x <= 0: + x = input("Too small. Enter a number greater than zero: ") + 6. Fix the following code: x = 10 @@ -59,6 +74,14 @@ print("Blast-off") + x = 10 + + while x > 0: + print(x) + x - 1 + + print("Blast-off") + 7. What is wrong with this code? It runs but it has unnecessary code. Find all the unneeded code. Also, answer why it is not needed. (1 pt) @@ -67,6 +90,11 @@ print(i) i += 1 + for i in range(10): + print(i) + + in the range on i, it's already established as 0 in default and the range increases each time, so adding one to i each time is pointless. + 8. Explain why the values printed for x are so different. (2 pts) # Sample 1 @@ -85,4 +113,6 @@ x += 1 print(x) + This is because of the indentation of the lines. The first sample adds one to x 10 times in i then another 10 in j, printing 20. Sample 2 adds has i add one, then goes to j to add 1 to x 10 more times, then repeats this 10 times. + diff --git a/Worksheets/worksheet_07.txt b/Worksheets/worksheet_07.txt index a87ff3f..1e34d42 100644 --- a/Worksheets/worksheet_07.txt +++ b/Worksheets/worksheet_07.txt @@ -8,6 +8,11 @@ 1. List the four types of data we've covered, and give an example of each: + + string - list = ["This", "is", "a", "string"] + Integer - list = [3, 1, 4, 1, 5, 9] + Floating point - list = [5.234, 6.234, 9.534] + Boolean - list = [True, 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, @@ -19,11 +24,15 @@ print(my_list[4]) print(my_list[5]) + It prints out 2, 101, then an error. + 3. What does this code print out? my_list=[5, 2, 6, 8, 101] for my_item in my_list: print(my_item) + + It prints out 5, 2, 6, 8, and 101 on separate lines. 4. What does this code print out? @@ -34,6 +43,8 @@ my_list2[2] = 10 print(my_list2) + It prints out an error. + 5. What does this code print out? my_list = [3 * 5] @@ -41,6 +52,8 @@ my_list = [3] * 5 print(my_list) + It prints out [15] then [3, 3, 3, 3, 3] + 6. What does this code print out? my_list = [5] @@ -48,6 +61,8 @@ my_list.append(i) print(my_list) + The code prints out 5, 0, 1, 2, 3, and 4 in square brackets. + 7. What does this code print out? print(len("Hi")) @@ -56,17 +71,23 @@ print(len("2")) print(len(2)) + This code prints out 2, 9, 8, and 1 on separate lines, then an error. + 8. What does this code print out? print("Simpson" + "College") print("Simpson" + "College"[1]) print( ("Simpson" + "College")[1] ) + It prints out SimpsonCollege, Simpsono, and i on separate lines. + 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 separate lines. 10. What does this code print out? @@ -75,17 +96,23 @@ word += "College" print(word) + This code prints out SimpsonCollegeCollegeCollege. + 11. What does this code print out? word = "Hi" * 3 print(word) + HiHiHi is printed out. + 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]) + It prints out "The 3rd spot is: " with a space at the end and "The -1 spot is: " with a . at the end. + 13. What does this code print out? s = "0123456789" @@ -93,9 +120,17 @@ print(s[:3]) print(s[3:]) + The code prints out 1, 012, and 3456789. + 14. Write a loop that will take in a list of five numbers from the user, adding each to an array. Then print the array. Try doing this without looking at the book. + +a_list = [] +for num_in_list in range(5): + user_number = input('Enter a number to add to the list: ') + a_list.append(int(user_number)) + print(a_list) 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 +140,10 @@ my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] +sum = 0 +my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] +for i in range(len(my_list)): + sum = sum + my_list[i] +average = sum// len(my_list) +print(average)