diff --git a/Lab 01 - Calculator/lab_01_part_a.py b/Lab 01 - Calculator/lab_01_part_a.py index 792d600..e1480c4 100644 --- a/Lab 01 - Calculator/lab_01_part_a.py +++ b/Lab 01 - Calculator/lab_01_part_a.py @@ -1 +1,7 @@ -# +#!/usr/bin/env python3 +# Calculator part a +# Christian Groves +# 11-1-17 +Fahrenheit = int(input('Enter temperature in Fahrenheit: ')) +Celcius = ((Fahrenheit - 32) / 1.8) +print(str(Celcius)) \ No newline at end of file diff --git a/Lab 01 - Calculator/lab_01_part_b.py b/Lab 01 - Calculator/lab_01_part_b.py index 792d600..151e7a0 100644 --- a/Lab 01 - Calculator/lab_01_part_b.py +++ b/Lab 01 - Calculator/lab_01_part_b.py @@ -1 +1,9 @@ -# +#!/usr/bin/env python3 +# Calculator part a +# Christian Groves +# 11-1-17 +print('Area of a trapezoid') +height = int(input('Enter the height of the trapezoid: ')) +bottombase = int(input('Enter the length of the botom base: ')) +topbase = int(input('Enter the length of the top base: ')) +print('The area is: ' + str((1/2)*(bottombase + topbase) * height)) \ 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..23b3007 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 +# Calculator part a +# Christian Groves +# 11-1-17 +import math +print('Area of a Square') +sidelen = int(input('Enter side lenght: ')) +areasquare = sidelen ** 2 +print('Area of the Square is: ' + str(areasquare)) \ 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..8546345 100644 --- a/Lab 03 - Create a Quiz/main_program.py +++ b/Lab 03 - Create a Quiz/main_program.py @@ -1 +1,49 @@ -# +#!/user/bin/env python3 +#Create a Quiz +#Christian Groves +#11-3-17 +counter = 0 +print('Pop Quiz') +answer1 = input('''What is the largest free to play game on PC: ''') +if answer1.lower() == 'warframe': + print('Correct') + counter += 1 +else: + print('Incorrect') + +answer2 = input('''When comes after 20013: ''') +if answer2 == '20014': + print('Correct') + counter += 1 +else: + print('Incorrect') + +answer3 = input('''What is the powerhouse of the cell: ''') +if answer3.lower() == 'mitochondria': + print('Correct') + counter += 1 +else: + print('Incorrect') + +answer4 = input('''What is the answer to the universe: ''') +if answer4 == '42': + print('Correct') + counter += 1 +else: + print('Incorrect') + +print('A. You') +print('B. Bill Gates') +print('C. Rick and Morty') +answer5 = input('''Who is dead: ''') + +if answer5.lower() == 'b': + print('Correct') + counter += 1 +else: + print('Incorrect') +if counter >= 4: + print("Congrats, you didn't fail") + print('Your score is ' + str(counter * 20) +'.0 percent.') +else: + print('Your score was terrible only a ' + str(counter * 20) + '.0 percent.') \ No newline at end of file diff --git a/Lab 04 - Camel/main_program.py b/Lab 04 - Camel/main_program.py index 792d600..aed0074 100644 --- a/Lab 04 - Camel/main_program.py +++ b/Lab 04 - Camel/main_program.py @@ -1 +1,83 @@ -# +#!/usr/bin/env python3 +#Camel +#Christian Groves +#11/9/17 +import random +print('Welcome to Camel!') +print('You have stolen a camel to make your way across the great Mobi desert.') +print('The natives want their camel back and are chasing you down! Survive your') +print('desert trek and out run the natives.') +done = False +oasis = 0 +miles = 0 +thirst = 0 +cameltired = 0 +nativestravel = -20 +cantinedrinks = 3 +alive = True +while done is False: + print('A. Drink from your canteen.') + print('B. Ahead moderate speed.') + print('C. Ahead full speed.') + print('D. Stop for the night.') + print('E. Status check.') + print('Q. Quit.') + userchoice = input('Your choice? ') + oasis = random.randrange(0, 20) + if userchoice.upper() == 'Q': + done = True + elif userchoice.upper() == 'D': + cameltired = 0 + print('Your camel is happy.') + nativestravel += random.randrange(7, 14) + elif userchoice.upper() == 'E': + print('Miles traveled: '+ str(miles)) + print('Drinks in canteen: ' + str(cantinedrinks)) + print('The natives are '+ str(nativestravel) + ' miles behind you.') + elif userchoice.upper() == 'C': + randomint = random.randrange(10, 20) + miles += randomint + print('Miles traveled ' + str(randomint)) + nativestravel += random.randrange(7, 14) + cameltired += random.randrange(1, 3) + thirst += 1 + elif userchoice.upper() == 'B': + randomint = random.randrange(5, 12) + miles += randomint + print('Miles traveled ' + str(randomint)) + nativestravel += random.randrange(7, 14) + cameltired += 1 + thirst += 1 + elif userchoice.upper() == 'A': + if cantinedrinks > 0: + cantinedrinks -= 1 + thirst = 0 + else: + print('Error') + if thirst > 4 and not thirst > 7 and done != True: + print('You are thirsty.') + elif thirst > 6 and done != True: + print('You died of thirst!') + done = True + alive = False + if cameltired > 5 and not cameltired > 9 and done != True: + print('Your camel is getting tired') + elif cameltired > 8 and done != True: + print('Your camel is dead.') + done = True + alive = False + if nativestravel > miles and done != True: + print('They have caught you') + alive = False + elif (nativestravel + 15) > miles and not nativestravel > miles: + print('The natives are getting close') + if oasis == 2: + print('You have found a oasis') + cantinedrinks = 3 + cameltired = 0 + thirst = 0 + if miles >= 200: + if done != True: + print('You win') + 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..b7994d0 100644 --- a/Lab 05 - Create a Picture/main_program.py +++ b/Lab 05 - Create a Picture/main_program.py @@ -1 +1,52 @@ -# +#!/usr/bin/env python3 +#Lab #5 +#Christian Groves +#11/16/17 +import pygame +pygame.init() +greenColor = 175 +radius = 180 +sunChange= (200,greenColor,40) +LIGHTBLUE=(126,213,242) +BLACK =(0,0,0) +WHITE =(255,255,255) +GREEN =(0,255,0) +RED =(255,0,0) +BLUE =(0,0,255) +PURPLE =(150,20,130) +size=(700,500) +xoff= 700 +screen = pygame.display.set_mode(size) +pygame.display.set_caption("Christian's Cool Game") +done = False +clock = pygame.time.Clock() +font = pygame.font.Font(None, 25) +while done == False: + screen.fill(BLUE) + #green ground + pygame.draw.line(screen, GREEN , [0,400], [700,400],200) + #first cloud + pygame.draw.ellipse(screen, WHITE, [40, 20, 130, 90]) + pygame.draw.ellipse(screen, WHITE, [70, 30, 140, 110]) + pygame.draw.ellipse(screen, WHITE, [20, 40, 140, 110]) + #second cloud + pygame.draw.ellipse(screen, WHITE, [440, 50, 140, 110]) + pygame.draw.ellipse(screen, WHITE, [460, 20, 140, 110]) + pygame.draw.ellipse(screen, WHITE, [480, 60, 140, 110]) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done=True + + #House's + for xoff in range(700, 0, -200): + pygame.draw.rect(screen, PURPLE, [50+ xoff , 260, 100, 110]) + pygame.draw.rect(screen, BLACK, [70+ xoff , 300, 30, 70]) + pygame.draw.rect(screen, WHITE, [110+ xoff , 300, 30, 30]) + pygame.draw.polygon(screen, RED, [[25+ xoff , 260], [175+ xoff, 260], [100+ xoff , 200]]) + + + pygame.display.flip() + + clock.tick(20) + +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..ea96405 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 +#Christian Groves +#11-15-17 +#for loop to add +num = 10 +for row in range(1,10): + for col in range(row,0,-1): + print(num,end=' ') + num += 1 + print() diff --git a/Lab 06 - Loopy Lab/part_2.py b/Lab 06 - Loopy Lab/part_2.py index 792d600..39f93e9 100644 --- a/Lab 06 - Loopy Lab/part_2.py +++ b/Lab 06 - Loopy Lab/part_2.py @@ -1 +1,20 @@ -# +#!/usr/bin/env python3 +#Lab #6 +#Christian Groves +#11-15-17 + +#input for desired size +boxsize = int(input('Desired size: ')) +horizontal = boxsize*2 +spaces = (boxsize*2) -3 +verticle = boxsize-1 + +#for loop to add the rows of o's +for row in range(1): + print('o'*horizontal) +#for loop to add the col +for col in range(1,verticle): + print('o',' '*spaces,end='o\n') +#for loop to add the rows at the end with o's +for row in range(1): + print('o'*horizontal) diff --git a/Lab 06 - Loopy Lab/part_3.py b/Lab 06 - Loopy Lab/part_3.py index 792d600..c6f170d 100644 --- a/Lab 06 - Loopy Lab/part_3.py +++ b/Lab 06 - Loopy Lab/part_3.py @@ -1 +1,23 @@ -# +#!/usr/bin/env python3 +#Lab #6 +#Christian Groves +#11-15-17 +size = int(input('Size: ')) + + +for row in range(1,10): + for digit1 in range(9 - row): + print(digit1, end=' ') + for spaces in range(1,row +1): + print(' ',end=' ') + for digit2 in range(row,0,-1): + print(digit2,end=' ') + print() +for botrow in range (9,0,-1): + for spacesbot in range(9- botrow, 0, -1): + print(' ',end=' ') + for digit3 in range(1, botrow+1): + print(digit3,end=' ') + for digit4 in range(botrow,0,-1): + print(digit4,end=' ') + print() \ 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..45eaa43 100644 --- a/Lab 06 - Loopy Lab/part_4.py +++ b/Lab 06 - Loopy Lab/part_4.py @@ -1 +1,56 @@ -# +#!/usr/bin/env python3 +#Lab 6 part 4 +#Christian Groves +#11/21/17 +import pygame + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) + +pygame.init() + +# Set the width and height of the screen [width, height] +size = (700, 500) +screen = pygame.display.set_mode(size) + +pygame.display.set_caption("My Game") + +# Loop until the user clicks the close button. +done = False + +# Used to manage how fast the screen updates +clock = pygame.time.Clock() + +# -------- Main Program Loop ----------- +while not done: + # --- Main event loop + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + # --- Game logic should go here + + # --- Screen-clearing code goes here + + # Here, we clear the screen to white. Don't put other drawing commands + # above this, or they will be erased with this command. + + # If you want a background image, replace this clear with blit'ing the + # background image. + screen.fill(BLACK) + for x in range(0,700, 5): + for y in range(0,500,5): + pygame.draw.rect(screen, GREEN, [1 + x,1 + y ,2,2]) + # --- Drawing code should go here + + # --- 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() \ No newline at end of file diff --git a/Lab 07 - Adventure/main_program.py b/Lab 07 - Adventure/main_program.py index 792d600..d4509b0 100644 --- a/Lab 07 - Adventure/main_program.py +++ b/Lab 07 - Adventure/main_program.py @@ -1 +1,101 @@ -# +#!/usr/bin/env python3 +#Lab 6 Maze Game +#Christian Groves +#11/20/17 + +'''Maze adventure''' + +roomList = [] +#CMN +room = ['You are in Computer Maintinance Networking.', 3, None, None, None] +roomList.append(room) +#CSD +room = ['You are in Computer Software Development.', 4, None, None, None] +roomList.append(room) +#HALL0 +room = ['You are in the West Hallway.', 5, 3, None, None] +roomList.append(room) +#HALL1 +room = ['You are in the Central Hallway.', 6, 4, 0, 2] +roomList.append(room) +#HALL2 +room = ['You are in the East Hallway.', 7, None, 1, 3] +roomList.append(room) +#BATHROOM +room = ['You are in the Bathroom.', None, None, 2, None] +roomList.append(room) +#WELDING +room = ['You are in Welding.', None, None, 3, None] +roomList.append(room) +#AUTO +room = ['You are in Auto Collision.', None, None, 4, None] +roomList.append(room) + +nextRoom = 0 +currentRoom = 0 + +done = False +while done == False: + posibleRooms = [] + print() + print(roomList[currentRoom][0]) + if (roomList[currentRoom][1]) != None: + posibleRooms.append('North ') + if (roomList[currentRoom][2]) != None: + posibleRooms.append('East ') + if (roomList[currentRoom][3]) != None: + posibleRooms.append('South ') + if (roomList[currentRoom][4]) != None: + posibleRooms.append('West ') + + print('You can go ',end = '') + for i in range(len(posibleRooms)): + print(str(posibleRooms[i]),end= ' ') + dirChoice = input('\nWhat direction do you want to go? ') + + #dirChoice direction + if dirChoice.upper()[0] == 'N': + dirChoice = 0 + elif dirChoice.upper()[0] == 'S': + dirChoice = 1 + elif dirChoice.upper()[0] == 'W': + dirChoice = 2 + elif dirChoice.upper()[0] == 'E': + dirChoice = 3 + elif dirChoice == 'cry': + print("\nCrying won't do anything for you! ") + continue + elif dirChoice.upper()[0] == 'Q': + break + + #North + if dirChoice == 0: + if (roomList[currentRoom][1]) == None: + print("\nYou can't go that way! ") + continue + else: + currentRoom = (roomList[currentRoom][1]) + + #South + if dirChoice == 1: + if (roomList[currentRoom][3]) == None: + print("\nYou can't go that way! ") + continue + else: + currentRoom = (roomList[currentRoom][3]) + + #West + if dirChoice == 2: + if (roomList[currentRoom][4]) == None: + print("\nYou can't go that way! ") + continue + else: + currentRoom = (roomList[currentRoom][4]) + + #East + if dirChoice == 3: + if (roomList[currentRoom][2]) == None: + print("\nYou can't go that way! ") + continue + else: + currentRoom = (roomList[currentRoom][2]) \ No newline at end of file diff --git a/Worksheets/worksheet_02.txt b/Worksheets/worksheet_02.txt index abe4cd7..a334c2c 100644 --- a/Worksheets/worksheet_02.txt +++ b/Worksheets/worksheet_02.txt @@ -6,37 +6,38 @@ 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.) - +0010 2 2. Give an example of a decimal number. - +.6 3. Give an example of a hexadecimal number. - +a2 4. Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal. - +1 2 4 8 16 5. What is a compiler? - +iIt changes our code to computer code 6. What is source code? - +Base code of a program in english 7. What is machine language? (Don't just say binary. That's not correct.) 8. What is a first generation language? (Don't just say binary. That's not correct.) 9. What is a second generation language? - +python2 10. What is a third generation language? (Explain, don't just give one example.) - +python3 it is the most up to date language that is faster and can do more complex +tasks than the last 11. What is an interpreter and how does it differ from a compiler? - +a interpeter translates from what we understand to what a computer can read 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. - +c sharp c++ java python 13. Look at the job boards and see what languages people are looking for. List the languages and the job board you looked at. - +JAVA and C++ bureau of labor statistics 14. What is the difference between the ``syntax'' and ``semantics'' of a language? - +syntax is a structure error meaning assigned 15. Pick a piece of technology, other than a computer you use regularly. Briefly describe the hardware and software that run on it. - +calculator diff --git a/Worksheets/worksheet_03.txt b/Worksheets/worksheet_03.txt index bc85b84..7c55196 100644 --- a/Worksheets/worksheet_03.txt +++ b/Worksheets/worksheet_03.txt @@ -15,9 +15,21 @@ if it is positive, negative, or zero. Use a proper if/elif/else chain, don't just use three if statements. +innum = input('Enter a number: ') +if innum > 0: + print('Positive') +elif innum < 0 + print('Negative') +else: + print('Zero') + 3. Write a Python program that will take in a number from a user and print out ``Success'' if it is greater than -10 and less than 10, inclusive. (1 pt) - + +innum = input('Enter a number: ') +if innum >= -10 and innum <= 10 + print('Success') + 4. This runs, but there is something wrong. What is it? (1 pt) user_input = input("A cherry is a: ") @@ -27,24 +39,30 @@ print("Correct!") else: print("Incorrect.") - +it will always answer incorrect unless A is the input B has no specific +response + 5. There are two things wrong with this code that tests if x is set to a positive value. One prevents it from running, and the other is subtle. Make sure the if statement works no matter what x is set to. Identify both issues. (2 pts) - x == 4 - if x >= 0: + x = 4 + if x > 0: print("x is positive.") else: print("x is not positive.") - +less than or equal to is no longer a issue and x is now equal to 4 instead +of compared to 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") - +no int() on the input, it does not compare x to 3 but uses a invalid sign, +nothing happens unless 3 is input + 7. There are four things wrong with this code. Identify all four issues. (4 pts) answer = input("What is the name of Dr. Bunsen Honeydew's assistant? ") @@ -52,13 +70,16 @@ print("Correct!") else print("Incorrect! It is Beaker.") - +answer is not the same as "a", the indentions are messed up, else is missing a +colon, the if statment needs to be == so that it will compare them + 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 will always print('that is good to hear!') + 9. Look at the code below. Write you best guess here on what it will print. Next, run the code and see if you are correct. Clearly label your guess and the actual answer. @@ -78,37 +99,43 @@ print("Fizz") if z: print("Buzz") - +buzz +Output: +x= 5 +y= False +z= True +Buzz + 10. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts) x = 5 y = 10 z = 10 - print(x < y) - print(y < z) - print(x == 5) - print(not x == 5) - print(x != 5) - print(not x != 5) - print(x == "5") - print(5 == x + 0.00000000001) - print(x == 5 and y == 10) - print(x == 5 and y == 5) - print(x == 5 or y == 5) + print(x < y) true + print(y < z) false + print(x == 5) true + print(not x == 5) invalid + print(x != 5) false + print(not x != 5) invalid + print(x == "5") invalid + print(5 == x + 0.00000000001) false + print(x == 5 and y == 10) true true + print(x == 5 and y == 5) true false + print(x == 5 or y == 5) true false 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) - print("3" == "3") - print(" 3" == "3") - print(3 < 4) - print(3 < 10) - print("3" < "4") - print("3" < "10") - print( (2 == 2) == "True" ) - print( (2 == 2) == True ) - print(3 < "3") + print("3" == "3") true + print(" 3" == "3") false + print(3 < 4) true + print(3 < 10) true + print("3" < "4") true + print("3" < "10") false + print( (2 == 2) == "True" ) false + print( (2 == 2) == True ) true + print(3 < "3") invalid 12. What things are wrong with this section of code? @@ -131,5 +158,5 @@ money = 50 - +it should be elif for ocupation b and c and there should be a else statment asking again if a invalid input is input. diff --git a/Worksheets/worksheet_05.txt b/Worksheets/worksheet_05.txt index 275a18a..367a73f 100644 --- a/Worksheets/worksheet_05.txt +++ b/Worksheets/worksheet_05.txt @@ -7,63 +7,67 @@ 1. Explain how the computer coordinate system differs from the standard Cartesian coordinate system. There are two main differences. List both. - +the top left coordinates are 0,0 and the x increases normaly where as the y increases as 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 +pygame.init() 3. Explain how WHITE = (255, 255, 255) represents a color. - +it shows all of the colors in a RGB spectrum first number being red second green and third blue when combined in full intesity\ +they are 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.) 5. What does the pygame.display.set_mode() function do? - +it is used to set the size 6. What does this for event in pygame.event.get() loop do? - +it checks each time a event happens and then executes everything in its loop 7. What is pygame.time.Clock used for? - +it is used to set the refreshrate 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 tells where to draw this line + * What does [0, 0] do? it tells the first x,y cord + * What does [100, 100] do? it tells the second x,y cord + * What does 5 do? it tells the width of the line 9. What is the best way to repeat something over and over in a drawing? - +loop it in a while loop 10. When drawing a rectangle, what happens if the specified line width is zero? - +nothing shows up 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 starts at the upper right corner of the elipse that not the center + * What is the length and the width of the ellipse? 230w x 80h pygame.draw.ellipse(screen, BLACK, [20, 20, 250, 100], 2) 12. When drawing an arc, what additional information is needed over drawing an ellipse? - +the radians are needed in order to determine the arc direction 13. Describe, in general, what are the three steps needed when printing text to the screen using graphics? - +you need the font, text with the color and size and finally you need to print it to the screen with blit 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. - +You don't need to keep defining the same thing 20 times a second when it only needs to be set once 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 cords are [50,100],[0,200],[200,200],[100,50] 16. What does pygame.display.flip() do? - +it displays all items drawn on the creen 17. What does pygame.quit() do? - +it closes 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. - + +it takes the surface, color, position, radius, and width +pygame.draw.circle(screen, BLACK, [50,50], 20, 1) diff --git a/Worksheets/worksheet_06.txt b/Worksheets/worksheet_06.txt index 35e5f13..dc9b101 100644 --- a/Worksheets/worksheet_06.txt +++ b/Worksheets/worksheet_06.txt @@ -17,6 +17,8 @@ while x < 10: print(x) x = x + 2 + guess print 0 2 4 6 8 all on new lines + actually prints 0 2 4 6 8 all on new lines 2. What does this program print out? @@ -24,6 +26,8 @@ while x < 64: print(x) x = x * 2 + guess print 1 2 4 8 16 32 all on new lines + actual print 1 2 4 8 16 32 all on new lines 3. Why is the and x >= 0 not needed? @@ -31,6 +35,7 @@ while x < 10 and x >= 0: print(x) x = x + 2 + x starts at 0 and never goes down so its always true 4. What does this program print out? (0 pts) Explain. (1 pt) @@ -40,6 +45,7 @@ if x == "1": print("Blast off!") x = x - 1 + guess 5, 4, 3, 2, 1, 0 no blast off because str 1 != int 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,30 +54,29 @@ while x <= 0: print("Too small. Enter a number greater than zero: ") - + x = float(input("Enter a number greater than zero: ")) 6. Fix the following code: x = 10 - while x < 0: + while x > 0: print(x) - x - 1 + 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 - + You do not need to set i to a number because it will be made in the for loop 8. Explain why the values printed for x are so different. (2 pts) # Sample 1 x = 0 - for i in range(10): + for i in range(10): each of these loops are only being ran once for a total of 20 runs in all x += 1 for j in range(10): x += 1 @@ -81,7 +86,7 @@ x = 0 for i in range(10): x += 1 - for j in range(10): + for j in range(10): this for loop is being done 10 times making it a total of 100 runs combined with the first it totals to 110 runs x += 1 print(x)