diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..fd78619 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,9 @@ -# +#!/usr/bin/env python3 +# Lab 01 +# Lauren Boehme +# 11/1/17 + +F=int(input('Enter temperature in fahrenheit: ')) +C=(F-32) * .5556 + +print('The temperature in celcius: ', c) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..ea94118 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,11 @@ -# +#!/usr/bin/env python3 +# Lab 01 +# Lauren Boehme +# 11/1/17 + +print('Area of a trapezoid: ') +height= int(input('Enter the height of a trapezoid: ')) +base= int(input('Enter the length of the bottom base: ')) +top= int(input('Enter the length of the top base: ')) +A= 1/2 *(base+top) * height +print('There area is: ', A) diff --git a/Lab 01 - Calculator/lab_01_part_c.py b/Lab 01 - Calculator/lab_01_part_c.py index 792d600..25af36a 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,9 @@ -# +#!/usr/bin/env python3 +# Lab 01 +# Lauren Boehme +# 11/1/17 + +PI = int(3.14159) +radius=int(input('What is the radius of the circle? ') +circle_rad = PI * (radius)**2 +print(circle_rad) diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..7dc9f70 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,57 @@ -# +#!/usr/bin/env python3 +# The Dank Quiz +# Lauren Boehme +# 11/3/17 +# Defining Score variables +x = 0 +score = x + +# Question 1 +print("Who is impossible to defeat?") +answer_1 = input("a)Sans\nb)Flowey\nc)Asriel\nd)None if you are filled with determination\n:") +if answer_1.lower() == "d" or answer_1.lower() == "None": + print("Correct") + x = x + 1 +else: + print("Incorrect, you are filled with determination.") + +# Question 2 +print("Who is the current president of the United States?") +answer_2 = input("a)Barack Obama\nb)Kanye\nc)A clown\nd)Walugi\n:") +if answer_2.lower() == "c" or answer_2.lower() == "a clown": + print("Correct") + x = x + 1 +else: + print("Incorrect , it's orange babyhand clownmcgee. Walugi 2020.") + +# Question 3 +print("True or False: Dogs are better than cats.") +answer_3 = input(":") +if answer_3.lower() == "true" or answer_3.lower() == "t": + print("Correct") + x = x + 1 +else: + print("Incorrect") + +# Question 4 +print("Whos is the best Smash Bros character?") +answer_4 = input("a)Kirby\nb)Doctor Mario\nc)Olimar\nd)Fox\n:") +if answer_4.lower() == "a" or answer_4 == "Kirby": + print("Correct") + x = x + 1 +else: + print("You're wrong- everyone knows that Kirby is the roundest and the strongest.") + +# Question 5 +print("True or False... Gun is the most powerful enemy in Contra?") +answer_5 = input(":") +if answer_5.lower() == "false" or answer_5.lower() == "f": + print("Correct, watch out for Dog.") + x = x + 1 +else: + print("Incorrect, watch out for Dog.") + + +# Score +score = float(x / 5) * 100 +print(x,"correct. That's",score, "%") diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..32910b7 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,54 @@ -# +#!/usr/bin/env python3 +# Princess Theif +# Lauren Boehme +# 11/7/17 + +import random + +print('Welcome to Camel! ') +print('You have stolen a camel to make your way across the great Mobi desert. The natives want their camel back and they are coming after you! Survive the desert and out run the natives. ') + +done = False +c_thirst = 0 +c_tired = 0 +miles_traveled = 0 +distance_natives = -20 +drinks_canteen = 4 + + +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 and rest.') + print('E. Status check.') + print('Q. Quit.') + print() +usranswer=input('Your choice: ') +if usranswer.upper() == 'Q': + done = True +elif usranswer.upper() == 'E': + print('Miles traveled: ', miles_traveled) + print('Drinks in canteen: ', drinks_canteen) + print('The natives are ', distance_natives, 'miles behind you. ') + +elif usranswer.upper() == 'D': + c_tired = 0 + print('The camel is happy!') + distance_natives =distance_natives + random_native +elif usranswer.upper() == 'C': + miles_traveled = miles_traveled + random_forward + print('You traveled', str(miles_traveled) + ' miles.') + camel_thirst = camel_thirst + 1 + camel_tired = camel_tired + 1 + distance_natives = distance_natives + random_native +elif usranswer.upper() == 'B': + print('You traveled', str(random_moderate) + ' miles.') +elif usranswer.upper() == 'A': diff --git a/Lab 06 - Loopy Lab/part_1.py b/Lab 06 - Loopy Lab/part_1.py index 8b13789..94c4717 100644 --- a/Lab 06 - Loopy Lab/part_1.py +++ b/Lab 06 - Loopy Lab/part_1.py @@ -1 +1,12 @@ +# !/usr/bin/env python3 +#Lab 6 part one +#Lauren Boehme +#11/15/17 +k=10 +for i in range(9): + for j in range(i+1): + print(k, end=' ') + k+=1 + print(' ', end=' ') + print() diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..68f6534 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,11 @@ -# +# !/usr/bin/env python3 +#Lab 6 part two +#Lauren Boehme +#11/15/17 + +numb = int(input("Enter number of o's: ")) +spaces= (numb*2) - 2 +print('o' * ((numb) * 2)) +for i in range(1, numb -1): + print('o' + (' '*spaces) + 'o') +print('o'*(numb)*2) diff --git a/Lab 06 - Loopy Lab/part_3.py b/Lab 06 - Loopy Lab/part_3.py index 792d600..6e5c6eb 100644 --- a/Lab 06 - Loopy Lab/part_3.py +++ b/Lab 06 - Loopy Lab/part_3.py @@ -1 +1,27 @@ -# +# !/usr/bin/env python3 +#Lab 6 part three +#Lauren Boehme +#11/15/17 +inValue = int(input('Input integer:')) + +base = ' ' +for i in range(inValue): + base = ' '+str(2*(inValue-1-i)+1)+base+str(2*(inValue-1-i)+1)+' ' + +length = len(base.strip()) +graph = [] +for j in range(inValue): + line = ' ' + for k in range(j): + line = ' ' + line + ' ' + for i in range(inValue-j): + line = ' '+str(2*(inValue-1-i)+1)+line+str(2*(inValue-1-i)+1)+' ' + line = line.strip() + length_temp = int((length-len(line))/2) + for m in range(length_temp): + line = ' ' + line + ' ' + graph.append(line) +for j in range(inValue) : + graph.append(graph[inValue-1-j]) +for line in graph: + print(line) diff --git a/Lab 06 - Loopy Lab/part_4.py b/Lab 06 - Loopy Lab/part_4.py index 792d600..daa2321 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,72 @@ -# +# !/usr/bin/env python3 +#Lab 6 part two +#Lauren Boehme +#11/15/17 + +""" + 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 = (900, 700) +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(WHITE) + + # --- Drawing code should go here + pygame.draw.circle(screen, GREEN[150,150],3, 0) + + + # --- Go ahead and update the screen with what we've drawn. + pygame.display.update() + + # --- Limit to 60 frames per second + clock.tick(60) + +# Close the window and quit. +pygame.quit() + + + diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..7b8edc9 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -1,27 +1,30 @@ - Chapter 01 Worksheet + Chapter 01 Worksheet Lauren Boehme When writing answers to questions, please use proper grammar, capitalization, and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. +print("Lauren") 2. How do you enter a comment in a program? - +enter comments using '#' 3. What do the following lines of code output? ALSO: Why do they give a different answer? - print(2 / 3) - print(2 // 3) + print(2 / 3) division =0.6 + print(2 // 3) floor division rounds the answer down to the nearest integer. =0 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. +pi = 3.141596 5. Why does this code not work? A = 22 print(a) +it doesnt work because they arent integers. You can use int() to fix this. 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? @@ -33,6 +36,7 @@ area area_of_rectangle Area_Of_Rectangle + Area_Of_Rectangle is the best name. 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 @@ -43,11 +47,11 @@ APPLE Apple2 1Apple - account number + account number not allowed account_number account.number accountNumber - account# + account# not allowed pi PI fred @@ -55,20 +59,21 @@ GreatBigVariable greatBigVariable great_big_variable - great.big.variable + great.big.variable 2x x2x - total% - #left + total% not allowed + #left not allowed 8. Why does this code not work? print(a) a = 45 - +because a isn't specified as an integer. 9. Explain the mistake in this code: pi = float(3.14) +it should look like this: pi= int(float(3.14)) 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -77,8 +82,10 @@ x = 3.14 pi = x area = pi * radius ** 2 + print(area) +should be pi = area 11. Explain the mistake in the following code: x = 4 @@ -86,6 +93,8 @@ a = ((x) * (y)) print(a) +should change a to area + 12. Explain the mistake in the following code: x = 4 @@ -93,6 +102,8 @@ a = 3(x + y) print(a) +python cannot do multiplication this way + 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) @@ -102,27 +113,44 @@ print(2/3+4) print(2 / 3 + 4) print( 2 / 3+ 4 ) + +Yes they all print the same value. print(2 / 3 + 4) is probably the best to use because it is the easiest to read and best organized. 15. What is a constant? + + true, false, or none. 16. How are variable names for constants different than other variable names? + they aren't just a word that the user can set, they have a meaning and will trigger an effect. + 17. What is a single quote and what is a double quote? Give and label an example of both. + +'- single +"- double 18. Write a Python program that will use escape codes to print a double-quote and a new line using the Window's standard. (Note: I'm asking for the Window's standard here. Look it up out of Chapter 1.) + +print('\"', \n) 19. Can a Python program print text to the screen using single quotes instead of double quotes? + +Yes, it does not matter which one you use. 20. Why does this code not calculate the average? print(3 + 4 + 5 / 3) +Because python does not understand order or operations that way. + 21. What is an ``operator'' in Python? + +a word that performs an operatiom 22. What does the following program print out? @@ -130,16 +158,20 @@ x + 1 print(x) +the program prints out 3. + 23. Correct the following code: user_name = input("Enter your name: )" +it should be user_name = input("Enter your name: ) + 24. Correct the following code: value = int(input(print("Enter your age"))) - +correct: value = int(input("Enter your age")) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..bcedd6a 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,60 @@ 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.) + +001 2. Give an example of a decimal number. + +352 3. Give an example of a hexadecimal number. + +015 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. + +1,2,8,16 5. What is a compiler? +a written program that becomes a code that a computer will process 6. What is source code? + words that form a working program 7. What is machine language? (Don't just say binary. That's not correct.) + a language that uses readable hexadecimal or binary. 8. What is a first generation language? (Don't just say binary. That's not correct.) + Altair 8800, The machine language + 9. What is a second generation language? + assembly language- programmer endures low levels of detail in the hardware to preform simple, common coding tasks. 10. What is a third generation language? (Explain, don't just give one example.) + include common language features such as variables, coinstants, if then, loops, and error handling. Uses a compiler to turn the code into a machine code. The higher the GL a language is, the closer it is to human english. 1gl being far from, 4gl being the most simple to try to interperet. 11. What is an interpreter and how does it differ from a compiler? + + They interperet code into machine language, which can be run in any format. A compiler only compiles into a machines native language. Both run 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. + + http://www.businessinsider.com/the-9-most-popular-programming-languages-according-to-the-facebook-for-programmers-2017-10/#1-javascript-15 + Javascript, python, java, ruby, php, c++, css, c#, go 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://stackoverflow.com/jobs +Most jobs call for python. 14. What is the difference between the ``syntax'' and ``semantics'' of a language? - +Syntax refers to strucure of a language but semantics deal with the meaning assigned to 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 cellphone. The device has speakers, a touchscreen , a camera, gps, access to the internet, runs apps, makes calls diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..8004f49 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -10,10 +10,20 @@ print("It is hot outside.") else: print("It is not hot out.") + +Temperature's input needs int 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. + + num= int(input('Enter a number: ') +if num=0: + print(num) +elif num > 0 or num < 0: + print(num) +else: + print('That is not a valid number.') 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) @@ -27,6 +37,8 @@ print("Correct!") else: print("Incorrect.") + + should be if user_input.lower 5. There are two things wrong with this code that tests if x is set to a positive value. One prevents it from running, and the other is subtle. @@ -39,11 +51,17 @@ else: print("x is not positive.") + Should be x=4 and should be >=1 or >0 + 6. What three things are wrong with the following code? (3 pts) x = input("Enter a number: ") if x = 3 print("You entered 3") + + if x=3 needs to have : + if x==3 not x=3 + The print statement isn't working 7. There are four things wrong with this code. Identify all four issues. (4 pts) @@ -52,6 +70,11 @@ print("Correct!") else print("Incorrect! It is Beaker.") + + else needs : , + a needs to be answer still or set a to the value of answer + it should be if a == beaker not a = beaker + incorrect indentation will cause error to functions 8. This program doesn't work correctly. What is wrong? (1 pt) @@ -59,6 +82,7 @@ if x == "Happy" or "Glad": print("That is good to hear!") + It says that is good to hear no matter what. You need an else statement 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. @@ -79,6 +103,10 @@ if z: print("Buzz") + the program will print the values of the variables and either fizz or buzz + + the program printed x=5, y=f, z=t, and 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 +125,9 @@ print(x == 5 and y == 5) print(x == 5 or y == 5) + it prints t,f,t,f,t,t,f,f,t,f,t + + 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,12 +141,23 @@ print( (2 == 2) == True ) print(3 < "3") +the program prints an error. 12. What things are wrong with this section of code? The programmer wants to set the money variable according to the initial occupation the user selects. (1 pt) - print("Welcome to Oregon Trail!") + print("Welcome to Oregon Trail!")True +False +True +False +False +True +False +False +True +False +True print("A. Banker") print("B. Carpenter") @@ -130,6 +172,8 @@ else if user_input = C: money = 50 - + the if_user_input should have more options, such as a, banker, A. + Money was never defined + Doesn't ask what you want, it's not very desciptive diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..897fbdf 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -13,17 +13,33 @@ 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('Lauren') + 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 a 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, 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. + +while int(launch) >0: +print(str(launch)) +launch= int(launch)-1 +print('Blast Off!') 5. There are three things wrong with this program. List each. (3 pts) @@ -35,11 +51,23 @@ total = total + i print("The total is:", x) - 6. Write a program that prints a random integer from 1 to 10 (inclusive). + x= input('enter a number') + total== total +i + print statement incorrect + + 6. Write a program that prints a random integer from 1 to 10 (inclusive).] + + import random + print(random.randint(1,10)) + #or it may be 1- 11? I cant remember if the zero thing applies here 7. Write a program that prints a random floating point number somewhere between 1 and 10 (inclusive). Do not make the mistake of generating a random number from 0 to 10 instead of 1 to 10. + + for top in range(0,11) + print(float(top)) + 8. Write a Python program that will: (3 pts) @@ -49,6 +77,23 @@ and the number of negative entries. Use an if, elif, else chain, not just three if statements. +total = 0 +posi = 0 +zeros = 0 +neg = 0 +num = input('Enter 7 numbers') +num = num.split() +for number in num: +totalnum = total + int(number) +if int(number) > 0: +posi =+ 1 +elif int(number) < 0: +neg =+ 1 + else: +zeros += 1 +print(totalnum) + print(posi, zeros, neg) + 9. Coin flip tosser: (4 pts) * Create a program that will print a random 0 or 1. @@ -57,6 +102,21 @@ * 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 trial in range(50): + num= random.randint(0,2) + if num == 1: + tails+=1 + else: + heads+=1 + print('Tails: ', str(tails), 'Heads: ', (str(heads)) + + + + 10. Write a program that plays rock, paper, scissors: (4 pts) * Create a program that randomly prints 0, 1, or 2. @@ -67,3 +127,37 @@ * Add conditional statement to figure out who wins. + import random + for Choice in range(2): + numb = random.randint(0,3) +if numb == 0: + cmptr = 'scissors' +elif numb == 1: + cmptr = 'rock' +else: + cmptr = 'paper' + player = input('Rock\nPaper\nScissors\nChoose: ') + if player.lower() == comp: + print('Its a draw!') + else: +if player == 'rock': + print('You Win!') + else: + print('My scissors won.) + elif cmptr == 'rock': + if player == 'paper': + print('You Win!') + else: + print('My rock won.) + else: + if player == 'scissors': + print('You Win!') + else: + print('My paper won.) + + + + + + + diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..afee179 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,14 @@ while x < 10: print(x) x = x + 2 + + it will print even numbers to 8 + it prints +0 +2 +4 +6 +8 2. What does this program print out? @@ -24,6 +32,18 @@ while x < 64: print(x) x = x * 2 + + Itll print multiples of 64. + + It prints +1 +2 +4 +8 +16 +32 + + 3. Why is the and x >= 0 not needed? @@ -32,6 +52,8 @@ print(x) x = x + 2 + it isn't needed because it will always be true, never false. + 4. What does this program print out? (0 pts) Explain. (1 pt) x = 5 @@ -41,24 +63,33 @@ print("Blast off!") x = x - 1 + it does not print blast off because integers and strings are not equal. + 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) x = float(input("Enter a number greater than zero: ")) - - while x <= 0: - print("Too small. Enter a number greater than zero: ") + + + while x <= 0: + print("Too small. Enter a number greater than zero: ") + + if x>= 0: + print() + + 6. Fix the following code: x = 10 - while x < 0: + while x > 0: print(x) x - 1 + print("Blast-off") - + print() 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 +97,8 @@ for i in range(10): print(i) i += 1 + + the i + 1 is unnecessary. 8. Explain why the values printed for x are so different. (2 pts) @@ -83,6 +116,10 @@ x += 1 for j in range(10): x += 1 + + print(x) + Because the print statement has added indents which tells the program that it is seperate so it does not print the code, it just prints a space(as x would not be defined) +