diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..02e214b 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,5 @@ -# +# The formula for F to C is F-32*5/9=C. +s = input("Enter temperature in Fahrenheit: ") +f = int(s) +c = (f - 32)*5/9 +print("The temperature in Celsius:", c, ) diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..fbbaeda 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,11 @@ -# +print('Area of a Trapezoid') +high = input('Enter the height of the trapezoid: ') +lbottom = input('Enter the length of the bottom base: ') +ltop = input('Enter the length of the top base: ') + +h = int(high) +lb = int(lbottom) +lt = int(ltop) +a = ((lb + lt) / 2)*h +A = str(a) +print('The 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..90ff2e3 100644 --- a/Lab 01 - Calculator/lab_01_part_c.py +++ b/Lab 01 - Calculator/lab_01_part_c.py @@ -1 +1,4 @@ -# +from math import pi +r = float(input ("Input the radius of the circle : ")) +print("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2)) + diff --git a/Lab 02 - Computer History/Chapter 2 report on video.docx b/Lab 02 - Computer History/Chapter 2 report on video.docx index c4ed613..89bd773 100644 --- a/Lab 02 - Computer History/Chapter 2 report on video.docx +++ b/Lab 02 - Computer History/Chapter 2 report on video.docx @@ -1 +1,12 @@ -Report goes here + Part 1 +https://www.youtube.com/watch?v=sX5g0kidk3Y + Part 2 +https://www.youtube.com/watch?v=X7bbQW2RLug + Part 3 +https://www.youtube.com/watch?v=6l3gs2UHXGU + + + +Adam Zeh +11/08/17 + Report on the Triumph of the Nerds diff --git a/Lab 03 - Create a Quiz/main_program.py b/Lab 03 - Create a Quiz/main_program.py index 792d600..92c31ea 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,37 @@ -# +print("Quiz Time!") + + +Q1 = input("What is the rarest ore in Minecraft? ") +if Q1 == "Emerald": + print('Correct!') +else: + print('Wrong!') + + +Q2 = input("What does Pinocchio in Italian mean? ") +if Q2 == "Pine eyes": + print('Correct!') +else: + print('Wrong!') + + +Q3 = input("In 1992, which US state began offering tourist info at 1-800-33-GUMBO? ") +if Q3 == 'Louisiana': + print('Correct!') +else: + print('Wrong!') + + +Q4 = input("Proteus orbits what planet of the solar system? ") +if Q4 == 'Neptune': + print('Correct!') +else: + print('Wrong!') + + +Q5 = input("What is the most popular animal eaten before it's born and after it's dead? ") +if Q5 == 'Chicken': + print('Correct!') +else: + print('Wrong!') + diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..2433261 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,97 @@ -# +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 are chasing you down! Survive your desert trek and out run the natives.""") +print() + +#variables +milesTraveled = 0 +thirst = 0 +camelFatigue = 0 +nativesTraveled = -20 +canteen = 3 +done = False +oasis = 0 + +#start main loop +while not done: + nativesBehind = milesTraveled - nativesTraveled + fullSpeed = random.randrange(10, 21) + moderateSpeed = random.randrange(5, 13) + print(""" + A. Drink from your canteen. + B. Ahead at moderate speed. + C. Ahead full speed. + D. Stop for the night. + E. Status check + Q. Quit.""") + print() + userInput = input("Your choice? ") + if userInput.lower() == "q": + done = True + +#status + elif userInput.lower() == "e": + print("Miles traveled: ",milesTraveled) + print("Drinks in canteen: ",canteen) + print("Your camel has ",camelFatigue,"amount of fatigue.") + print("The natives are ",nativesBehind,"miles behind you.") +#stop for night + elif userInput.lower() == "d": + camelFatigue *= 0 + print("Your camel feels refreshed and happy his fatigue is now ",camelFatigue) + nativesTraveled += random.randrange(7, 15) +#move full speed + elif userInput.lower() == "c": + print("You traveled ",fullSpeed,"miles!") + milesTraveled += fullSpeed + thirst += 1 + camelFatigue += random.randrange(1, 4) + nativesTraveled += random.randrange(7, 15) + oasis = random.randrange(1, 21) + +#move moderate speed + elif userInput.lower() == "b": + print("You traveled ",moderateSpeed,"miles!") + milesTraveled += moderateSpeed + thirst += 1 + camelFatigue += 1 + nativesTraveled += random.randrange(7, 15) + oasis = random.randrange(1, 21) + + #drink canteen + elif userInput.lower() == "a": + if canteen == 0: + print("You're out of water.") + else: + canteen -= 1 + thirst *= 0 + print("You have ",canteen,"drinks left and you are no longer thirsty.") + +#not done check + if oasis == 20: + camelFatigue *= 0 + thirst *= 0 + canteen = 3 + print("You found an oasis! After taking a drink you filled your canteen and the camel is refreshed.") + if nativesBehind <= 15: + print("The natives are drawing near!") + if milesTraveled >= 200 and not done: + print("You made it across the desert, you win!") + done = True + if nativesTraveled >= milesTraveled: + print("The natives caught and beheaded you.") + print("You're dead!") + done = True + if thirst > 4 and thirst <= 6 and not done: + print("You are thirsty") + if thirst > 6: + print("You died of dehydration!") + done = True + if camelFatigue > 5 and camelFatigue <= 8 and not done: + print("Your camel is getting tired.") + if camelFatigue > 8: + print("Your camel is dead.") + done = True + diff --git a/Lab 05 - Create a Picture/main_program.py b/Lab 05 - Create a Picture/main_program.py index 792d600..c230d20 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,39 @@ -# +#Turtle Tim +import turtle + +def draw_diamond(some_turtle): + some_turtle.left(30) + some_turtle.forward(50) + some_turtle.right(60) + some_turtle.forward(50) + some_turtle.right(120) + some_turtle.forward(50) + some_turtle.right(60) + some_turtle.forward(50) + some_turtle.right(150) + +def draw_art(): + # Instantiate a Screen object, window. Then customize window. + window = turtle.Screen() + window.bgcolor("red") # set background color + # Instantiate a Turtle object, tim. Then customize tim. + tim = turtle.Turtle() + tim.shape("turtle") # see Turtle doc + tim.color("white") # see Turtle doc + tim.speed(2) # 1 (slowest) to 10 (fastest). 0 means no animation. + + # Draw a circle with 36 diamonds. We rotate each diamond by 10 degrees at a time. + for i in range (0, 75): + draw_diamond(tim) + tim.right(5) + + # Draw a between middle of circle and the floor + tim.right(45) + tim.forward(200) + + # How to exit? + window.exitonclick() # click on the window to exit + + +# Invoke the procedure! +draw_art() diff --git a/Worksheets/worksheet_01.txt b/Worksheets/worksheet_01.txt index 728ad02..32ed4f0 100644 --- a/Worksheets/worksheet_01.txt +++ b/Worksheets/worksheet_01.txt @@ -6,70 +6,71 @@ and punctuation. Please limit the length of each line to 80 characters. 1. Write a line of code that will print your name. - +print('Adam') 2. How do you enter a comment in a program? - +# hi there 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) 0.6 + print(2 // 3) 2/3 4. Write a line of code that creates a variable called pi and sets it to an appropriate value. - +from math import pi +pi = pi 5. Why does this code not work? A = 22 print(a) - + one of the variables is not capitalized 6. All of the variable names below can be used. But which ONE of these is the better variable name to use? - a + a A Area AREA area - area_of_rectangle + area_of_rectangle <--- this one Area_Of_Rectangle 7. Which of these variables names are not allowed in Python? (More than one might be wrong. Also, this question is not asking about improper names, just names that aren't allowed. Test them if you aren't sure.) - apple - Apple - APPLE - Apple2 - 1Apple - account number + apple x + Apple x + APPLE x + Apple2 x + 1Apple x + account number x account_number account.number - accountNumber - account# - pi + accountNumber x + account# x + pi x PI - fred - Fred - GreatBigVariable - greatBigVariable + fred x + Fred x + GreatBigVariable x + greatBigVariable x great_big_variable - great.big.variable - 2x + great.big.variable x + 2x x x2x - total% - #left + total% x + #left x 8. Why does this code not work? print(a) a = 45 - + the variable needs to be before the print statement 9. Explain the mistake in this code: pi = float(3.14) - + the integer isnt long enough 10. This program runs, but the code still could be better. Explain what is wrong with the code. @@ -78,67 +79,66 @@ pi = x area = pi * radius ** 2 print(area) - + no one knows what x means 11. Explain the mistake in the following code: x = 4 y = 5 a = ((x) * (y)) print(a) - + its a str, not an int statement 12. Explain the mistake in the following code: x = 4 y = 5 a = 3(x + y) print(a) - + a isnt defined 13. Explain the mistake in the following code: radius = input(float("Enter the radius:")) - + float needs to be before input 14. Do all these print the same value? Which one is better to use and why? - print(2/3+4) + print(2/3+4) <--- this one print(2 / 3 + 4) print( 2 / 3+ 4 ) 15. What is a constant? - +something that stays the same. 16. How are variable names for constants different than other variable names? - +they dont change 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.) 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) - +bc python uses order of operations 21. What is an ``operator'' in Python? - +its a math symbol 22. What does the following program print out? x = 3 x + 1 - print(x) + print(x) it prints out 3 - 23. Correct the following code: - user_name = input("Enter your name: )" + username = input("Enter your name: )" 24. Correct the following code: - value = int(input(print("Enter your age"))) + value = int(input("Enter your age")) diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..ab1691e 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,307 @@ 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.) - +011010100101101 2. Give an example of a decimal number. - +82 3. Give an example of a hexadecimal number. - +D1CE 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. - +1 2 4 8 16 5. What is a compiler? - +a program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer. 6. What is source code? - +a text listing of commands to be compiled or assembled into an executable computer program. 7. What is machine language? (Don't just say binary. That's not correct.) - + a computer programming language consisting of binary or hexadecimal instructions that a computer can respond to directly. 8. What is a first generation language? (Don't just say binary. That's not correct.) - +a machine-level programming language. 9. What is a second generation language? - + a generational way to categorize assembly languages 10. What is a third generation language? (Explain, don't just give one example.) - +a generational way to categorize high-level computer programming languages. 11. What is an interpreter and how does it differ from a compiler? - +a program that can analyze and execute a program line by line. 12. Search the web and find some of the most popular programming languages. List the website(s) you got the information from and what the languages are. + + https://dzone.com/articles/big-list-256-programming + +4th Dimension/4D +ABAP +ABC +ActionScript +Ada +Agilent VEE +Algol +Alice +Angelscript +Apex +APL +AppleScript +Arc +Arduino +ASP +AspectJ +Assembly +ATLAS +Augeas +AutoHotkey +AutoIt +AutoLISP +Automator +Avenue +Awk +Bash +(Visual) Basic +bc +BCPL +BETA +BlitzMax +Boo +Bourne Shell +Bro +C +C Shell +C# +C++ +C++/CLI +C-Omega +Caml +Ceylon +CFML +cg +Ch +CHILL +CIL +CL (OS/400) +Clarion +Clean +Clipper +Clojure +CLU +COBOL +Cobra +CoffeeScript +ColdFusion +COMAL +Common Lisp +Coq +cT +Curl +D +Dart +DCL +DCPU-16 ASM +Delphi/Object Pascal +DiBOL +Dylan +E +eC +Ecl +ECMAScript +EGL +Eiffel +Elixir +Emacs Lisp +Erlang +Etoys +Euphoria +EXEC +F# +Factor +Falcon +Fancy +Fantom +Felix +Forth +Fortran +Fortress +(Visual) FoxPro +Gambas +GNU Octave +Go +Google AppsScript +Gosu +Groovy +Haskell +haXe +Heron +HPL +HyperTalk +Icon +IDL +Inform +Informix-4GL +INTERCAL +Io +Ioke +J +J# +JADE +Java +Java FX Script +JavaScript +JScript +JScript.NET +Julia +Korn Shell +Kotlin +LabVIEW +Ladder Logic +Lasso +Limbo +Lingo +Lisp +Logo +Logtalk +LotusScript +LPC +Lua +Lustre +M4 +MAD +Magic +Magik +Malbolge +MANTIS +Maple +Mathematica +MATLAB +Max/MSP +MAXScript +MEL +Mercury +Mirah +Miva +ML +Monkey +Modula-2 +Modula-3 +MOO +Moto +MS-DOS Batch +MUMPS +NATURAL +Nemerle +Nimrod +NQC +NSIS +Nu +NXT-G +Oberon +Object Rexx +Objective-C +Objective-J +OCaml +Occam +ooc +Opa +OpenCL +OpenEdge ABL +OPL +Oz +Paradox +Parrot +Pascal +Perl +PHP +Pike +PILOT +PL/I +PL/SQL +Pliant +PostScript +POV-Ray +PowerBasic +PowerScript +PowerShell +Processing +Prolog +Puppet +Pure Data +Python +Q +R +Racket +REALBasic +REBOL +Revolution +REXX +RPG (OS/400) +Ruby +Rust +S +S-PLUS +SAS +Sather +Scala +Scheme +Scilab +Scratch +sed +Seed7 +Self +Shell +SIGNAL +Simula +Simulink +Slate +Smalltalk +Smarty +SPARK +SPSS +SQR +Squeak +Squirrel +Standard ML +Suneido +SuperCollider +TACL +Tcl +Tex +thinBasic +TOM +Transact-SQL +Turing +TypeScript +Vala/Genie +VBScript +Verilog +VHDL +VimL +Visual Basic .NET +WebDNA +Whitespace +X10 +xBase +XBase++ +Xen +XPL +XSLT +XQuery +yacc +Yorick +Z shell 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. + https://www.forbes.com/sites/jeffkauflin/2017/05/12/the-five-most-in-demand-coding-languages/#4eb47115b3f5 +SQL +Java +Javascript +C# +Python +C++ +PHP +iOS +Ruby + 14. What is the difference between the ``syntax'' and ``semantics'' of a language? - +Syntax refers to formal rules governing the construction of valid statements in a language. Semantics refers to the set of rules which give the meaning of a statement. 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - +My Nintendo 3DS and it runs on the netfront web browser diff --git a/Worksheets/worksheet_04.txt b/Worksheets/worksheet_04.txt index 341b2fa..af1a77e 100644 --- a/Worksheets/worksheet_04.txt +++ b/Worksheets/worksheet_04.txt @@ -14,16 +14,40 @@ 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. +word = input('Name: ') + +for i in range(10): + print(word) + +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.) + + word = input("Q: ") + +for i in range(20): + print('Red') + print('Gold') 3. Write a Python program that will use a for loop to print the even numbers from 2 to 100, inclusive. +for i in range(0, 101): + if (i % 2 == 0): + 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: + print (countdown), + countdown -= 1 +print('0') +print("Blastoff!") 5. There are three things wrong with this program. List each. (3 pts) @@ -35,11 +59,21 @@ total = total + i print("The total is:", x) + first they forgot to put int( before the input + then they shouldve put total = total + x + finally they shouldve put print("The total is:", total) + 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. + +from random import * +print(uniform(1, 10)) 8. Write a Python program that will: (3 pts) @@ -47,7 +81,7 @@ * Print the total sum of the numbers * Print the count of the positive entries, the number entries equal to zero, and the number of negative entries. Use an if, elif, else chain, not just three - if statements. + if statements. 9. Coin flip tosser: (4 pts) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt deleted file mode 100644 index 35e5f13..0000000 --- a/Worksheets/worksheet_06.txt +++ /dev/null @@ -1,88 +0,0 @@ - - Chapter 06 Worksheet - - - For each of the first two questions, write out your best guess as to what the - code will print. Clearly label this as your guess. Then run the code and look at - the output. Write if your guess was correct. If it was not, briefly describe what - was different and why. - - Predicting what the code will do is important in writing programs, and - figuring out why programs don't run the way expected. - - 1. What does this program print out? - (Remember: TWO answers. Your guess and the actual result. Label both.) - - x = 0 - while x < 10: - print(x) - x = x + 2 - - 2. What does this program print out? - - x = 1 - while x < 64: - print(x) - x = x * 2 - - 3. Why is the and x >= 0 not needed? - - x = 0 - while x < 10 and x >= 0: - print(x) - x = x + 2 - - 4. What does this program print out? (0 pts) Explain. (1 pt) - - x = 5 - while x >= 0: - print(x) - if x == "1": - print("Blast off!") - x = x - 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) - - x = float(input("Enter a number greater than zero: ")) - - while x <= 0: - print("Too small. Enter a number greater than zero: ") - - 6. Fix the following code: - - 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) - - i = 0 - for i in range(10): - print(i) - i += 1 - - 8. Explain why the values printed for x are so different. (2 pts) - - # Sample 1 - x = 0 - for i in range(10): - x += 1 - for j in range(10): - x += 1 - print(x) - - # Sample 2 - x = 0 - for i in range(10): - x += 1 - for j in range(10): - x += 1 - print(x) - -