diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..fd0aa41 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,10 @@ -# +#!/usr/bin/env/ python3 +# Calculator Part a +# Brady Ballmann +# 11/01/2017 + +fahrenheit = int(input("Enter a tempature in Fahrenheit: ")) + +celcius = (fahrenheit - 32) * 5/9 + +print('The temperature in celcius:', celcius) diff --git a/Lab 01 - Calculator/lab_01_part_a.py.save b/Lab 01 - Calculator/lab_01_part_a.py.save new file mode 100644 index 0000000..0ac9f55 --- /dev/null +++ b/Lab 01 - Calculator/lab_01_part_a.py.save @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +# Lab 1: Custom Calculators Part a +# Brady Ballmann +# 11/01/2017 + +fahrenheit = input(' diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..34dd0bd 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,8 @@ -# +print('Area of a trapezoid') +height = int(input("Enter the height of the trapezoid: ")) +length_btm = int(input("Enter the length of the bottom base: ")) +length_top = int(input("Enter the length of the top base: ")) + +area = ((length_btm + length_top) / 2) * 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..7e79e0f 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,8 @@ -# +import math + +print('Area of an equilateral triangle') +area_side = int(input('Length of a side: ')) + +area = (math.sqrt(3)/4)*(area_side * area_side) + +print('The Area of the triangle:',area) diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..96d0fb0 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 +# Creating a quiz +# Brady Ballmann +# 11/03/2017 + +percentage = 0 + +print('Ready for a quiz? :)') + +question_one = input('Who won the 2017 World Series? ') +if question_one.lower() == "astros": + print("Correct!") + percentage += 1 +else: + print('Incorrect!') + +question_two = int(input("What is 5 * 432 / 4? ")) +if question_two == 540: + print("Correct!") + percentage += 1 +else: + print("Incorrect!") + +print("What is the most common male name in the US?") +print("1. James") +print("2. Robert") +print("3. David") +print("4. Michael") +print("TIP! Enter the number not the name") +question_three = int(input('? ')) +if question_three == 1: + print('Correct!') + percentage += 1 +else: + print("Incorrect!") + + +question_four = int(input("What is 10 to the power of 3? ")) +if question_four == 1000: + print("Correct!") + percentage += 1 +else: + print("Incorrect!") + +print('If an apple weighs about 3 and 1/2 ounces. What is the radius of the sun? ') +print("1. 432,288 mi") +print("2. 542,421 mi") +print("3. 674,321 mi") +print("4. 132,424 mi") +print("TIP! Enter the number not the name.") +question_five = int(input('? ')) +if question_five == 1: + print('Correct!') + percentage += 1 +else: + print("Incorrect!") + +percent = percentage * 20 +print("You got" , percentage, "out of 5") +print(percent, "percent! Congrats!") + + + + + + + + + diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..2456b27 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,80 @@ -# +import random + +print("Welcome to Camel!") +print("You have stolen a camel to make your way across the great Mobie desert.") +print("The natives want their camel back and are chasing you down! Survive your") +print("desert trek and out run the natives.") + +done = False +camel_thirst = 0 +camel_tired = 0 +miles_traveled = 0 +distance_natives = -20 +drinks_canteen = 3 + + +random_oasis = random.randrange(1 , 21) + +random_forward = random.randrange(10 , 21) + +random_native = random.randrange(7 , 15) + +random_tiredness = random.randrange(1 , 4) + +random_moderate = random.randrange(5, 13) + + +while not done: + 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.") + print() + user_answer = input("Your choice? ") + if user_answer.upper() == "Q": + done = True + elif user_answer.upper() == "E": + print("Miles traveled:", miles_traveled) + print("Drinks in canteen: ", drinks_canteen) + print("The natives are", str(distance_natives) + " miles behind you") + elif user_answer.upper() == "D": + camel_tired = 0 + print("The camel is happy :D") + distance_natives = distance_natives + random_native + elif user_answer.upper() == "C": + miles_traveled = miles_traveled + random_forward + print("You traveled", str(miles_traveled) + " miles.") + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + random_tiredness + distance_natives = distance_natives + random_native + elif user_answer.upper() == "B": + print("You traveled", str(random_moderate) + " miles.") + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + 1 + distance_natives = distance_natives + random_native + elif user_answer.upper() == "A": + drinks_canteen = drinks_canteen - 1 + camel_thirst = 0 + elif not done and camel_thirst < 4: + print("You are thirsty") + elif not done and camel_thirst < 6: + print("You died") + done = True + elif camel_tired > 5: + print("Your camel is getting tired") + elif camel_tired > 8: + print("Your camel is dead") + done = True + elif distance_natives >= miles_traveled: + print("The natives have caught you") + done = True + elif miles_traveled >= 200: + print("YOU WON!") + elif random_oasis == 10: + print("You found an oasis") + drink_canteen = 3 + camel_thirst = 0 + camel_tired = 0 + diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..ddcf3b5 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,113 @@ -# +#!/usr/bin/env python3 +# main_program for chapter 5 lab +# Brady Ballmann +# 11/09/2017 + + +import pygame + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +BLUE = (0, 0, 255) +GREEN = (0, 100, 0) +RED = (255, 0, 0) +YELLOW = (255, 255, 0) +SKY = (135, 206, 250) +BROWN = (139,69,19) +WHEAT = (245,222,179) + +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(SKY) + + # These are Lines and they are the tree + pygame.draw.line(screen, BROWN, [10, 600], [10, 400], 10) + + pygame.draw.line(screen, BROWN, [85, 600], [85, 400], 10) + + pygame.draw.line(screen, BROWN, [160, 600], [160, 400], 10) + + pygame.draw.line(screen, WHEAT, [300, 470], [300, 400], 5) + + pygame.draw.line(screen, WHEAT, [300, 470], [270, 600], 5) + + pygame.draw.line(screen, WHEAT, [300, 470], [350, 600], 5) + + pygame.draw.line(screen, WHEAT, [275, 440], [325, 440], 5) + + pygame.draw.line(screen, BROWN, [690, 600], [690, 400], 10) + + pygame.draw.line(screen, BROWN, [625, 600], [625, 400], 10) + + pygame.draw.line(screen, BROWN, [550, 600], [550, 400], 10) + + pygame.draw.line(screen, BLACK, [375, 600], [375, 475], 7) + + pygame.draw.line(screen, BLACK, [450, 600], [450, 475], 7) + + pygame.draw.line(screen, BLACK, [375, 475], [450, 475], 5) + + + + + # Circles + + pygame.draw.circle(screen, GREEN, (20,350), 65,0) + + pygame.draw.circle(screen, GREEN, (90,350), 65,0) + + pygame.draw.circle(screen, GREEN, (160,350), 65,0) + + pygame.draw.circle(screen, WHEAT, (300,400), 20,0) + + pygame.draw.circle(screen, WHITE, (295,395), 3,0) + + pygame.draw.circle(screen, WHITE, (305,395), 3,0) + + pygame.draw.circle(screen, GREEN, (690,350), 65,0) + + pygame.draw.circle(screen, GREEN, (620,350), 65,0) + + pygame.draw.circle(screen, GREEN, (550,350), 65,0) + + pygame.draw.circle(screen, YELLOW, (20,20), 80,0) + + + # --- 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 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..298e58c 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,6 @@ - +start = 10 +for row in range(9): + for column in range(row+1): + print(start ,end=" ") + start+=1 + print() diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..da84f5b 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,17 @@ -# +#!/usr/bin/env python3 +# part_2 of chapter 6 Lab +# Brady Ballmann +# 11/15/2017 + +# Input statement for the o's +numberos = int(input("How many o's do you want? ")) + + +# Print for the top of the box +print('o'*(numberos*2 )) +# Loop for the spaces +for i in range(numberos -2): + print("o" + ' '*(numberos*2 -2 ) + 'o') +# Print the bottom o's +print('o'*(numberos*2)) + diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..2b349a8 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,78 @@ -# +""" + Simple graphics demo + + Sample Python/Pygame Programs + Simpson College Computer Science + http://programarcadegames.com/ + http://simpson.edu/computer-science/ + +""" + +# Import a library of functions called 'pygame' +import pygame +import random + +# Initialize the game engine +pygame.init() + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +BLUE = (0, 0, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) +YELLOW = (255, 255, 0) +SKY = (135, 206, 250) +BROWN = (139,69,19) +PI = 3.141592653 + + +# Set the height and width of the screen +size = (700, 500) +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("Professor Craven's Cool Game") + +# Loop until the user clicks the close button. +done = False +clock = pygame.time.Clock() + +# Loop as long as done == False +while not done: + + for event in pygame.event.get(): # User did something + if event.type == pygame.QUIT: # If user clicked close + done = True # Flag that we are done so we exit this loop + + # All drawing code happens after the for loop and but + # inside the main while not done loop. + + # Clear the screen and set the screen background + screen.fill(BLACK) + + + for y in range(0,500,10): + for x in range(0,700,10): + pygame.draw.rect(screen, GREEN, [x,y, 5, 5], 0) + print() + + + + + + + + + + # Go ahead and update the screen with what we've drawn. + # This MUST happen after all the other drawing commands. + pygame.display.flip() + + # This limits the while loop to a max of 60 times per second. + # Leave this out and we will use all CPU we can. + clock.tick(60) + +# Be IDLE friendly +pygame.quit() + + diff --git a/Lab 06 Loopy Lab/temp.py b/Lab 06 Loopy Lab/temp.py index 792d600..a889645 100644 --- a/Lab 06 Loopy Lab/temp.py +++ b/Lab 06 Loopy Lab/temp.py @@ -1 +1,30 @@ -# +#!/usr/bin/env python3 +# Loops +# Brady Ballmann +# 11/13/2017 + +# Do 9 times starting at 1 +for row in range(1, 10): + # Loop to print spaces + for space in range(9 - row): + print(" ", end=" ") + # Loop to print digits + for digits in range(1, row + 1): + print(digits, end=" ") + # Loop to print digits2 + for digits2 in range(row -1, 0, -1): + print(digits2, end=" ") + # Print a new line + print() +for row in range(10): + # Print spaces Loop + for space in range(row+1): + print(" ", end=" ") + # Loop to print digits + for digits in range(1,9-row): + print(digits, end=" ") + # Loop to print digits2 + for digits2 in range(7-row,0,-1): + print(digits2,end=" ") + # Print new line + print() \ No newline at end of file diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..6740997 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,96 @@ -# +#!/usr/bin/env python3 +# main_program chapter 07 +# Brady Ballmann +# 11/20/2017 + + +'''First draft of a Program to navigate through a dungeon''' +# Template of the room: [Room desc. , N, E, S, W] +room_list = [] + + +# 0 +room = ["You are in an entrance room.",1,None,None,None] + +room_list.append(room) +# 1 +room = ["You are in the Diner. ",None,2,0,None] + +room_list.append(room) + +# 2 +room = ["You are in the bedroom hallway.",None,3,None,1] + +room_list.append(room) +# 3 +room = ["You are in the bedroom. ",4,None,None,2] + +room_list.append(room) +# 4 +room = ["You are in the hallway between the bathroom and the bedroom. ",5,None,3,None] + +room_list.append(room) +# 5 +room = ["You are in the Bathroom.",None,None,4,None] + +room_list.append(room) + + +current_room = 0 + +done = False + +while not done: + print() + print(room_list[current_room][0]) + + if room_list[current_room][1] != None: + print("There is an exit to the North") + if room_list[current_room][2] != None: + print("There is an exit to the East") + if room_list[current_room][3] != None: + print("There is an exit to the South") + if room_list[current_room][4] != None: + print("There is an exit to the West") + + user_direction = input("What direction would you like to go? ") + print() + # Printing the exits + + + if user_direction == "n" or user_direction == "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_direction == "e" or user_direction == "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_direction == "s" or user_direction == "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_direction == "w" or user_direction == "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("The program does not understand what you typed") + + + + + \ No newline at end of file diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..013fae5 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,23 +6,26 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. + print('Brady Ballmann') 2. How do you enter a comment in a program? + Using a # 3. What do the following lines of code output? ALSO: Why do they give a different answer? print(2 / 3) print(2 // 3) - + 1. Prints .6 repeating + 2. Prints 0 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. - +pi = 3.14 5. Why does this code not work? A = 22 print(a) - + Because the A variable is captial and the print a is not 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -31,23 +34,25 @@ Area AREA area - area_of_rectangle + area_of_rectangle Area_Of_Rectangle + area_of_rectangle is the best one because it uses _ to replace spaces and lower case letters + 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.) apple - Apple - APPLE - Apple2 - 1Apple - account number - account_number - account.number + Apple + APPLE + Apple2 + 1Apple + account number <--- This one + account_number + account.number <--- This one accountNumber - account# + account# <--- This one pi PI fred @@ -55,21 +60,25 @@ GreatBigVariable greatBigVariable great_big_variable - great.big.variable + great.big.variable <--- This one 2x x2x - total% - #left + total% <--- This one + #left <--- This one 8. Why does this code not work? print(a) a = 45 + because the print statement comes before the variable + 9. Explain the mistake in this code: pi = float(3.14) + It doesnt need to float + 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -79,6 +88,9 @@ area = pi * radius ** 2 print(area) + You could just set pi to 3.14 instead of making x = 3.14 + + 11. Explain the mistake in the following code: x = 4 @@ -86,6 +98,9 @@ a = ((x) * (y)) print(a) + The 3rd line does not need to be seperated by Quotations. + + 12. Explain the mistake in the following code: x = 4 @@ -93,36 +108,58 @@ a = 3(x + y) print(a) + They are not integers + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) + You need an int + 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 print the same thing but the 1st one is better to use because it is smaller and keeps the code looking nice :D. + 15. What is a constant? + A variable that doesnt change. + 16. How are variable names for constants different than other variable names? + + You can normally tell when a variable is a constant because they will be in CAPS 17. What is a single quote and what is a double quote? Give and label an example of both. + + "" '' 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('This \r\nis') 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) + Because that is not what you are asking it to do + 21. What is an ``operator'' in Python? + + Symbols that carry out logical computation. + + 22. What does the following program print out? @@ -130,15 +167,19 @@ x + 1 print(x) + 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('Your age is', value) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..ab2bb2e 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -1,4 +1,4 @@ - +Brady Ballmann Chapter 02 Worksheet @@ -7,36 +7,98 @@ binary, decimal, and hexadecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.) + 1010 + + 2. Give an example of a decimal number. + + 17 3. Give an example of a hexadecimal number. + A + + 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. + 0, 2, 4, 8, 16 + + 5. What is a compiler? + Turns source code into machine code + 6. What is source code? + Code the programmer enters + 7. What is machine language? (Don't just say binary. That's not correct.) + Machine code is what the computer interpretes source code into + 8. What is a first generation language? (Don't just say binary. That's not correct.) + A combination of 0 and 1's to represent numbers + It is the same thing as machine language + + 9. What is a second generation language? + Assembly language that uses a compiler to turn source code into machine code. + 10. What is a third generation language? (Explain, don't just give one example.) + + A high level computer programming language. Like python or C. Turns source code directly into machine code. 11. What is an interpreter and how does it differ from a compiler? + It runs source code and interprets it directly into machine code on the fly. + + It is diffirent because you can not switch between different computing machines like linux and windows. + 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. + This website: https://www.tiobe.com/tiobe-index// + + Top 10: + Java + C + C++ + C# + Python + JavaScript + PHP + Visual Basic .NET + Assembly language + Ruby + + + + + + + + 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. + Most jobs are looking for Java developers. + + https://www.dice.com/jobs?q=Developer&l=Saint+Charles%2C+MO&searchid=9954836866302&stst= + 14. What is the difference between the ``syntax'' and ``semantics'' of a language? + syntax deals with the structure/form of the code + + semantics deal with meaning assigned to that specific symbol, character, or word + + + + 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. + My phone has ram and an operating system(ios). The software is like the apps that I run on it. diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..561c05d 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,14 +10,41 @@ print("It is hot outside.") else: print("It is not hot out.") + + int instead of float 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("This number is positive") +elif number < 0: + print("This number is negative") +elif number == 0: + print("This number is 0") + + + + + + 3. Write a Python program that will take in a number from a user and print out ``Success'' if it is greater than -10 and less than 10, inclusive. (1 pt) + +number = int(input('Enter a number: ')) + +if number > -10 and number < 10: + print('Success') +else: + print('Wrong') + + + + 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -27,6 +54,8 @@ print("Correct!") else: print("Incorrect.") + + It ask the question before giving the options to the question. 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 +67,18 @@ print("x is positive.") else: print("x is not positive.") + + In the 1st line you only need 1 Equal sign(=). You should have an input statement instead of setting x to a certain number. 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") + + 1. On the 1st line there is no "int" + 2. On the 2nd line there needs to be a doube == and a : at the end(if x == 3:) + 3. The variable for the number is a bad variable(x) should be like "number" 7. There are four things wrong with this code. Identify all four issues. (4 pts) @@ -52,12 +87,25 @@ print("Correct!") else print("Incorrect! It is Beaker.") + + 1. Line 2 needs double = + 2. else doesnt have a : + 3. else needs to be indented correctly (lined up with the if statement all the way to the left) + 4.Print is not indented correctly. + + + 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!") + + It says "That is good to hear!" no matter what. You need to add on the right side of line 2 next to "Glad" x == "Glad":. (Line should look like this. + if 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 +126,13 @@ print("Fizz") if z: print("Buzz") + + Guess:Will print true and false statements. + + Answer: It ran x = 5, y = true, and z = true also printed Buzz because z was true. If you set y to == 5 it would also print Fizz. + + + 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 +152,34 @@ print(x == 5 and y == 5) print(x == 5 or y == 5) + + Guess: False + True + True + False + False + True + False + False + True + False + True + + Answer: 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) @@ -110,6 +193,26 @@ print( (2 == 2) == True ) print(3 < "3") + + Guess: True + False + True + True + False + False + True + True + False + Answer: True +False +True +True +True +False +False +True +error + 12. What things are wrong with this section of code? The programmer wants to set the money variable according to @@ -129,6 +232,12 @@ money = 70 else if user_input = C: money = 50 + + Well there is multiple things wrong. + + The else if needs to be a elif statement. + The "= B: needs to have " " around the B same goes with A and C + and you need to print the money amount so the user can see how much money.(Optional) diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..b0d9335 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,19 +13,51 @@ 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("Brady") + 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(5): + 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,102,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. - - 5. There are three things wrong with this program. List each. (3 pts) + + i = 10 + while i > -1: + print(i) + i -= 1 + print("Blast off!") + + + + + + + + + + 5.What three things are wrong with this program. List each. (3 pts) print("This program takes three numbers and returns the sum.") total = 0 @@ -34,13 +66,28 @@ x = input("Enter a number: ") total = total + i print("The total is:", x) + + + 1. Line 4 the x needs to be total. + 2. Line 3 I changed it to total += x + 3. Line 2 you need "int" on the input statement. x = int(input("Enter a number: ") 6. Write a program that prints a random integer from 1 to 10 (inclusive). + + import random + random_number = random.randrange(1,11) + print(random_number) + + 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 + random_number = random.random() * 10 + print(random_number) + 8. Write a Python program that will: (3 pts) * Ask the user for seven numbers @@ -49,6 +96,35 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. +total = 0 +count_pos = 0 +count_neg = 0 +count_zero = 0 +for i in range(7): + new_number = int(input("Enter a number: " )) + if new_number < 0: + count_neg += 1 + elif new_number > 0: + count_pos += 1 + elif new_number == 0: + count_zero += 1 + + + total += new_number + +print("The total is: ", total) +print(count_neg, "Negative numbers entered") +print(count_pos,"Positive numbers entered") +print(count_zero, "Zeros entered") + + + + + + + + + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +133,25 @@ * Add a loop so that the program does this 50 times. * Create a running total for the number of heads flipped, and the number of tails. +import random +heads = 0 +tails = 0 +for i in range(50): + rand_number = random.randrange(0, 2) + if rand_number == 1: + print("Heads") + heads += 1 + else: + print("Tails") + tails += 1 +print(tails, "Tails") +print(heads, "Heads") + + + + + + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -66,4 +161,49 @@ * (It will be easier if you have them enter 1, 2, or 3.) * Add conditional statement to figure out who wins. +import random + + +person_input = int(input("Choose between Rock(1),Paper(2) or, Scissors(3): ")) +if person_input == 3: + print("Scissors") +elif person_input == 2: + print("Paper") +else: + print("Rock") + +rand_number = random.randrange(0, 3) +if rand_number == 1: + print("Rock") +elif rand_number == 2: + print("Paper") +elif rand_number == 0: + print("Scissors") + +if person_input == 3 and rand_number == 2: + print("You win!") +elif person_input == 3 and rand_number == 1: + print("You lose!") +elif person_input == 3 and rand_number == 0: + print("Tie!") + + +elif person_input == 2 and rand_number == 2: + print("Tie!") +elif person_input == 2 and rand_number == 1: + print("You win!") +elif person_input == 2 and rand_number == 0: + print("You lose!") + +elif person_input == 1 and rand_number == 2: + print("You lose!") +elif person_input == 1 and rand_number == 1: + print("Tie!") +elif person_input == 1 and rand_number == 0: + print("You win!") + + + + + diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..8b5da89 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -8,62 +8,156 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. + 1.(0,0) the origin starts at the top left instead of the middle. + 2. The y coordinate is reversed as y goes up it goes down. + + 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. - + + It appears white for the backround usually + + + 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.) - + + Because it is a constant. When we want to change the value of the color we use lower case. + + + + + 5. What does the pygame.display.set_mode() function do? + + It opens the screen. + 6. What does this for event in pygame.event.get() loop do? + + That is for if the user does something in the program like clicking. + + 7. What is pygame.time.Clock used for? + + Used to manage how fast the screen updates. + 8. For this line of code: (3 pts) pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5) - * What does screen do? - * What does [0, 0] do? - * What does [100, 100] do? - * What does 5 do? + * What does screen do? It make sure that it draws it on the screen. Initialize + * What does [0, 0] do? Makes the starting point 0,0 + * What does [100, 100] do? Thats the end point. + * What does 5 do? 5 pixels wide + + + 9. What is the best way to repeat something over and over in a drawing? + Drawing it with a loop or offset + Use this code to draw multiple lines + y_offset = 0 + while y_offset < 100: + pygame.draw.line(screen,RED,[0,10+y_offset],[100,110+y_offset],5) + y_offset = y_offset + 10 + + + 10. When drawing a rectangle, what happens if the specified line width is zero? - + Nothing will appear + + + + 11. Describe the ellipse drawn in the code below. - * What is the x, y of the origin coordinate? - * What does the origin coordinate specify? The center of the circle? - * What is the length and the width of the ellipse? + * What is the x, y of the origin coordinate? 20,20 + * What does the origin coordinate specify? The center of the circle? It is the upper left like a rectangle but with no corners. + * What is the length and the width of the ellipse? 250 pixels wide and 100 tall. pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) 12. When drawing an arc, what additional information is needed over drawing an ellipse? + + + It includes the start and end angles for the arc to draw. 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? + + 1.Create a variable that holds the information + + 2. The program creates an image of the text. + + 3. Tell the program where to put the image. Like a stamp. + + + 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. + + Because if you keep it in the loop it will just keep drawing it over and over again. + + + + + 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) + these are the 4 points [50,100],[0,200],[200,200],[100,50] + + + + + + 16. What does pygame.display.flip() do? - + + It updates the screen with what we have drawn so far. It must happen after all drawing commands have been executed or else you will not see them on the scree. + + 17. What does pygame.quit() do? - + When you exit the screen no error will pop up. + + + 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, BLACK, (20,20), 20,0) + + + + + + + + + + + + + + diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..4d94fc7 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,14 @@ while x < 10: print(x) x = x + 2 + + + 0 + 2 + 4 + 6 + 8 + 2. What does this program print out? @@ -24,7 +32,12 @@ while x < 64: print(x) x = x * 2 - + 1 + 2 + 4 + 8 + 16 + 32 3. Why is the and x >= 0 not needed? x = 0 @@ -32,6 +45,11 @@ print(x) x = x + 2 + Because 0 is already = to 0 and it is less than 10. + + There is no way x can go down in value in this loop. + + 4. What does this program print out? (0 pts) Explain. (1 pt) x = 5 @@ -40,6 +58,20 @@ if x == "1": print("Blast off!") x = x - 1 + + 5 + 4 + 3 + 2 + 1 + 0 + + Does not print out blast off because x is == to the character 1. + + + + + 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 +80,16 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") + + + +ANSWER: x = float(input("Enter a number greater than zero: ")) + while x <= 0: + x = int(input("Too small. Enter a number greater than zero: ")) + You need to add an input and int on the statement in the while loop. Also set it to x + + + 6. Fix the following code: @@ -59,6 +101,19 @@ print("Blast-off") + + ANSWER: + + x = 10 + + while x > 0: + print(x) + x = x - 1 + if x == 0: + 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) @@ -66,6 +121,12 @@ for i in range(10): print(i) i += 1 + + + You don't need to set i to 0 because in range it will start at 0 automatically. Also you don't need the i += 1 because the for loop does that already. + + + 8. Explain why the values printed for x are so different. (2 pts) @@ -77,6 +138,7 @@ x += 1 print(x) + # Sample 2 x = 0 for i in range(10): @@ -85,4 +147,12 @@ x += 1 print(x) + + Because the second one has a nester for loop so it will go through way more times than than the one above. + + + + + + diff --git a/Worksheets/worksheet_07.txt b/Worksheets/worksheet_07.txt index a87ff3f..a56dd4e 100644 --- a/Worksheets/worksheet_07.txt +++ b/Worksheets/worksheet_07.txt @@ -9,6 +9,17 @@ 1. List the four types of data we've covered, and give an example of each: + String: String of characters or text("Hello World") + + Integer: A whole number(4,2,1,3,9, ect.. ) + + Floating point: A number with a decimal point.(1.32313131) + + Boolean: Two values either true or false(done = True) + + + + 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 +30,32 @@ print(my_list[4]) print(my_list[5]) + 2 + 101 + Out of range + + + + + + 3. What does this code print out? my_list=[5, 2, 6, 8, 101] for my_item in my_list: print(my_item) + + All the items. + 5 + 2 + 6 + 8 + 101 + + + + + 4. What does this code print out? @@ -34,6 +66,9 @@ my_list2[2] = 10 print(my_list2) + It wont work because you are trying to change a tuple + + 5. What does this code print out? my_list = [3 * 5] @@ -41,6 +76,10 @@ my_list = [3] * 5 print(my_list) + [15] + [3,3,3,3,3] + + 6. What does this code print out? my_list = [5] @@ -48,6 +87,12 @@ my_list.append(i) print(my_list) + [5,0,1,2,3,4] + + + + + 7. What does this code print out? print(len("Hi")) @@ -56,17 +101,39 @@ print(len("2")) print(len(2)) + 2 + 9 + 8 + 1 + Last one doesn't print because 2 is not a character. It is an Integer + 8. What does this code print out? print("Simpson" + "College") print("Simpson" + "College"[1]) print( ("Simpson" + "College")[1] ) + SimpsonCollege + Simsono + i + + + 9. What does this code print out? word = "Simpson" for letter in word: print(letter) + S + i + m + p + s + o + n + + + 10. What does this code print out? @@ -75,17 +142,27 @@ word += "College" print(word) + SimsonCollegeCollegeCollege + + + + + 11. What does this code print out? word = "Hi" * 3 print(word) + HiHiHi 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]) + The 3rd spot is: " " + The -1 spot is: . + 13. What does this code print out? s = "0123456789" @@ -93,16 +170,55 @@ print(s[:3]) print(s[3:]) + 1 + 01234567893456789 + + 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. + + user_list = [] + for i in range(5): + user_input = int(input( "Enter an integer: ")) + user_list.append(user_input) + print(user_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 the list size changes. (There is a sum function I haven't told you about. Don't use that. - Sum the numbers individually as shown in the chapter.) + Sum the numbers individually as shown in the chapter.) + + + my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4] + + + list_total = 0 + + + + for i in range(len(my_list)): + + list_total += my_list[i] + + + averagelist = list_total / len(my_list) + + print(averagelist) + + + + + + + - my_list = [3,12,3,5,3,4,6,8,5,3,5,6,3,2,4]