Python Programming Final Study Guide

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which operator allows you to create a string that is the result of putting two different strings together, side by side? / * + -

+

After the following code is executed, what cannot be the run results? import random r1 = random.randint(5, 15) print(r1) # Generates a random number between # two given negative range r2 = random.randint(-10, -2) print(r2) 5 -2 1 -10

1

If the following code was run, how far would Tracy move? width = 20 width = width * 2 If width > 40: turtle.forward(width) turtle.forward(100) - 100 pixels - 0 pixels - 25 pixels - 50 pixels

100 pixels

What is the value of num when this loop completes? num = 0 for i in range(2, 8, 2): num = num + i - 12 - 2 - 20 - 8

12

The Python Boolean type is one of Python's built-in data types. It's used to represent the truth value of an expression. For example, the expression 1 <= 2 is True or true, while the expression 0 == 1 is False or false. Is the above description of Python's built-in Boolean type correct? True False

False

After the execute print(myfunction()) statement, 6 will be printed on the console. def myfunction(): return 3+3 print(myfunction()) - True - False

True

If programmers write an if statement and the condition is false, what does Turtle do? - Turtle completes the indented code - The code stops running - Turtle gives us an error - Turtle skips the commands under the if statement

Turtle skips the commands under the if statement

Which of the following is NOT an example of using Top Down Design? - Writing code for one part of a function before tackling the whole thing - Using descriptive names for variables - Separating a large problems into smaller ones - Breaking a large code up into functions

Using descriptive names for variables

How many lines will this program print? while True: print("hi") - 0 - an infinite number of lines X - 1

an infinite number of lines X

Which is an example of the proper use of the Python input() function? answer = input("enter your answer: ") answer = INPUT(enter your answer: ) answer = INPUT("enter your answer: ") answer = input(enter your answer: )

answer = input("enter your answer: ")

Which of the following functions successfully returns double the variable 'number'? - def my_function(number): number*2 - def my_function(number*2): return - def my_function(number): return number*2 - def my_function(): return number

def my_function(number): return number*2

Which of the following is the correct way to declare a function in Python? - print_hello: print("hello") - function print_hello(): print("hello") - print_hello(): print("hello") - def print_hello(): print("hello")

def print_hello(): print("hello")

Which of the following code samples correctly creates a function that takes a single parameter and prints it? - def print_number(x): print(x) - def print_number(): print(parameter) - def print_number(): print(x) - def print(x)

def print_number(x): print(x)

What is the function name? The function is defined as follows. def drawMyTriangle(side): t.forward(side) # draw base t.left(120) t.forward(side) t.left(120) t.forward(side) - drawMyTriangle(side) - drawMyTriangle(16) - drawMyTriangle(4) - def drawMyTriangle(side):

drawMyTriangle(side)

Which of the following for loops will give the same values for i as the loop below? for i in range(10): - for i in range (10, 0, -1): - for i in range (0, 10): - for i in range (11, 0): - for i in range (11):

for i in range (0, 10):

Which of the following for loops would print the following numbers? 2 3 4 5 - for i in range(6): print(i) - for x in range(2, 6): print(x) - for i in range(5): print(i) - for i in range(0, 5, 1): print(i)

for x in range(2, 6): print(x)

Given that score has the value of 0. Which of the following chunks of code would display "WHATEVER" to the console? - if score == 0: print("YES") elif score < 0: print("WHATEVER") else: print("NO") - if score > 0: print("YES") elif score == 0: print("WHATEVER") else: print("NO") - if score == 0: print("YES") elif score == 0: print("WHATEVER") else: print("NO") - if score == 0: print("YES") elif score == 0: print("WHATEVER") else: print("NO")

if score > 0: print("YES") elif score == 0: print("WHATEVER") else: print("NO")

How would we write an if statement where Turtle will put the move forward 15 pixels if a variable called step was positive? - if step >= 0: turtle.forward(15) - if step > 0(): turtle.forward(15) - if step > 0: turtle.forward(15) - if steps > 0: turtle.forward(15)

if step > 0: turtle.forward(15)

Python with tkinter is the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy task. To create a tkinter app: 1.Importing the module - tkinter 2.Create the main window (container) 3.Add any number of widgets to the main window 4.Apply the event Trigger on the widgets. 5.How to import Tkinter in Python Replit? What is the first line of code for your TKinter app? - import tkinter - importing tkinter - Import Tkinter - Importing tkinter

import tkinter

The following program is designed to print out Emil Smith. Which of the function calls works? def my_function(fname, lname): print(fname + " " + lname) - my_function("Smith", "Emil") - my_function("Emil", "Smith") - my_function("Emil")

my_function("Emil", "Smith")

Which of the following prints E? - my_string = "ABCDE" print(my_string(0)) - my_string = "ABCDE" print(my_string[-5]) - my_string = "ABCDE" print(my_string[5]) - my_string = "ABCDE" print(my_string[-1])

my_string = "ABCDE" print(my_string[-1])

Which of the following prints the letter E? my_string = "ABCDE" print(my_string[1]) my_string = "ABCDE" print(my_string(0)) my_string = "ABCDE" print(my_string(1)) my_string = "ABCDE" print(my_string[0]) - my_string = "ABCDE" print(my_string[4]) - my_string = "ABCDE" print(my_string(1)) - my_string = "ABCDE" print(my_string[0]) - my_string = "ABCDE" print(my_string[3])

my_string = "ABCDE" print(my_string[4])

Which of the following calls to the following function will cause the "Happy" to appear on the console? def mystery(score = 42): if score == 42: print("Happy") else: print("Sad") - mystery(score, 42): - mystery(score(42)) - mystery(33) - mystery()

mystery()

Which of the following is True? A. not(5 > 71) B. not(5 < 71) C. not(5 != 71) - not(5 != 71) - not(5 < 71) - not(5 > 71)

not(5 > 71)

Which of the following expressions generates true when x is between 10 and 20 inclusive? - (x == 10) and (x <= 20) - (10 < x < 20) - (x <= 20) and (x >= 10) - (x >= 10) or (x <= 20) - (10 <= x <= 20)

(x <= 20) and (x >= 10)

Print a message based on whether the condition is True or False. What will be printed out? a = 200 b = 33 if b > a: print("Good") else: print("Not good") - Good - Nothing printed - Not good - Sometimes "Good" is printed, and sometimes "Not good" is printed

Not good

Given the following code, what is the output? x = "Python "y = "is " z = "awesome" print(x + z + y) - awesome is Python - Python awesome is - is Python awesome - Python is awesome

Python awesome is

The input() function in Python returns user input as a string. True False

True

True or False? The Python code below will print: True False False Python code: print(10 > 9) print(10 == 9) print(10 < 9) - True - False

True

What is the output of the following code? print(10 > 9) print(10 == 9) print(10 <= 10) - TrueFalseTrue - FalseFalseFalse - TrueFalseFalse - TrueTrueTrue - FalseFalseTrue

TrueFalseTrue

Choose the correct statement. a.Variables only represent strings in Python. b.Variables in Python can be initialized and assigned new values using the equals sign (=). c.New variables always start out as zero. d.The same variable in Python can be represented in either upper or lower case. - Variables in Python can be initialized and assigned new values using the equals sign (=) - The same variable in Python can be represented in either upper or lower case - Variables only represent strings in Python - New variables always start out as zero

Variables in Python can be initialized and assigned new values using the equals sign (=)

When would a for loop be a good control structure to use? - When you need to repeat something 5 times - When you don't know how many times something will need to repeat - When you need to repeat multiple command

When you need to repeat something 5 times

Which of the following simulates the flipping of a coin where one side is heads and one side is tails? - coin = random.randint(up, down) if coin == up: print("heads") else: print("tails") - coin = random.randint("heads", "tails") if coin == "heads": print("heads") else: print("tails") - coin = random.randint(1, 2) if coin == 0: print("heads") else: print("tails") - coin = random.randint(0, 1) if coin == 0: print("heads") else: print("tails")

coin = random.randint(0, 1) if coin == 0: print("heads") else: print("tails")

Given the following code that creates a "Click Me!" button that displays a popup that says "Hello World". import Tkinter import tkMessageBox top = Tkinter.Tk()def helloCallBack(): tkMessageBox.showinfo( "Hello Python", "Hello World") B = Tkinter.Button(top, text = "Click Me!", """mystery""") B.pack()top.mainloop() Which of the following could replace """mystery""" to make the button display a popup that says "Hello World"? - command = helloCallBack - "Hello World" - helloCallBack() - helloCallBack(command) - helloCallBack() = command;

command = helloCallBack

Which of the following code samples correctly passes the number 10 as an argument to the function print_number (num)? - print print_number print 10 - print_number() print 10 - 10(print_number) - print_number(10)

print_number(10)

How many possible values are there for a boolean variable? - 2 - 1 - 3 - There is an infinite number of possibilities.

2

How many lines will this program print? x = 10 while x > 0: print(x) x = x - 3 - 3 - 4 - 5 - 6

4

What will be printed on the console after the following program is executed? def myfunction(): return 3+3 print("Hello, World!") print(myfunction()) - 6 Hello, World! - Hello, World! 6 - 6 - Nothing

6

Which of the following best describes the purpose of a for loop? - A for loop is for doing something a fixed number of times. - A for loop is for doing something an indeterminate number of times. - A for loop is doing something an infinite number of times.

A for loop is for doing something a fixed number of times.

Top Down Design makes it easier to solve a problem, as it: - Starts with the biggest function and then moving to smaller ones. - Breaks the problem down into smaller parts - Starts your code from the first command. - Makes each function hold only one command

Breaks the problem down into smaller parts

Variables allow us to: a.Name different parts of our programs b.Use english words to communicate with Turtle c.Store information to use in our programs d.Change the words Turtle recognizes - B. Use english words to communicate with Turtle - A. Name different parts of our programs - D. Change the words Turtle recognizes - C. Store information to use in our program

C. Store information to use in our program

What is the name of the panel in EarSketch contains all of the assembled audio clips? - Content Manager - Code Editor - Curriculum - My Scripts - Digital Audio Workstation

Digital Audio Workstation

What does this program print? temperature = 65 while temperature < 80: print("It's still a nice day") if temperature < 70: temperature = temperature + 5 elif temperature > 75: print ("Do nothing!") else: temperature = temperature + 3 - It's still a nice day It's still a nice day It's still a nice day It's still a nice day It's still a nice day - It's still a nice day It's still a nice day - It's still a nice day It's still a nice day It's still a nice day It's still a nice day - It's still a nice day It's still a nice day It's still a nice day

It's still a nice day It's still a nice day It's still a nice day It's still a nice day It's still a nice day

You have used the Tk(screenName=None, baseName=None, className='Tk', useTk=1) method in your GUI app. TK() is a method to create a main window. To change the name of the window, you can change the className to the desired one. The basic code used to create the main window of the application is: m=tkinter.Tk() where m is the name of the main window object. To create the main window for your GUI application. What will you add to the following code segment? 1. import tkinter as tk 2. 3. window.title("Hello wold") 4. window.geometry("300x300") 5. hello = tk.Label(text="Hello world!") 6. hello.pack() 7. button = tk.Button(text="Click me!") 8. button.pack() 9. tk.mainloop() 10. - Line 2; window = tk.Tk() - Line 2; window = Tk.Tk() - Line 10; window = Tk().tk - Line 10; window = tk.Tk()

Line 2; window = tk.Tk()

Tkinter provides a mainloop()method. It is used when your application is ready to run. mainloop() is an infinite loop used to run the application, wait for an event to occur and process the event as long as the window is not closed. What is missing in the code segment below? import tkinter as tk m = tk.Tk() ''' widgets are added here ''' - The last statement is missing. It should be m.mainloop() - The 2nd statement is missing. It should be m.mainloop() - The last statement is missing. It should be m.Mainloop() - The last statement is missing. It should be mainloop()

The last statement is missing. It should be m.mainloop()

Why do programmers use if statements? - To have Turtle make decisions based on conditional statements - To tell Turtle to do something if we run our code - To tell Turtle to stop our code if there's an error - To have Turtle complete one function at a time

To have Turtle make decisions based on conditional statements

I have a pre-defined function drawMyTriangle(side) defined as follows. def drawMyTriangle(side): t.forward(side) # draw base t.left(120) t.forward(side) t.left(120) t.forward(side) I want to create an equilateral triangle with side = 16. All I need to do is to type the following statement in my Python program: drawMyTriangle(16) - True - False

True

Which of the following functions would draw a square with side length 50 with the following statement: drawSquare(50) - def drawSquare(side): for x in range(3): forward(side) turnRight(90) - def drawSquare(side): forward(side) turnRight(90) forward(side) turnRight(90) forward(side) turnRight(90) forward(side) turnRight(90) - def drawSquare(side): forward(side) forward(side) forward(side) turnRight(90) forward(side) turnRight(90) - def drawMySquare(side): forward(side) turnRight(90) forward(side) turnRight(90) forward(side) turnRight(90) forward(side) turnRight(90)

def drawSquare(side): forward(side) turnRight(90) forward(side) turnRight(90) forward(side) turnRight(90) forward(side) turnRight(90)

Which of the following functions successfully returns the number 10? - def my_function(): 10 - def my_function(10): return - def my_function(): return 10 - def my_function(): print(10)

def my_function(): return 10

Which of the following prints BCDE? - my_string = "ABCDE" print(my_string[1:]) - my_string = "ABCDE" print(my_string[2:]) - my_string = "ABCDE" print(my_string[3:5]) - my_string = "ABCDE" print(my_string[2:4])

my_string = "ABCDE" print(my_string[1:])

There are a number of widgets which you can put in your tkinter application. Which of the following are not a widget? - Button - pack() - Label - Entry

pack()

Consider the code block below. What are the values of x and y when this while loop finishes executing? x = 2 y = 5 while (y > 2 and x < y): x = x + 1 y = y - 1 - x = 2; y = 5 - x = 4; y = 2 - x = 5; y = 2 - x = 4; y = 3

x = 4; y = 3

Given the following function definition, which of the following code snippets will display 25 on the console? def yeet(apple): return apple * apple - yeet(5) - x = yeet(5) print(x) - print(yeet(apple)) - x = yeet(5 * 5) print(x)

x = yeet(5) print(x)

What is a correct Python expression for checking to see if a number stored in a variable x is between 0 and 5? - x > 0 and x < 5 - x > 0 or x < 5 - x > 0 or < 5 - x > 0 and < 5

x > 0 and x < 5

Which of the following is true for both 7 and 24? - x > 0 and x < 5 - not x > 0 and x < 5 - x > 0 or x < 5 - x < 0 or x < 5

x > 0 or x < 5


Set pelajaran terkait

Chapter 8 NCLEX & back of book and worksheet

View Set

Foundations Of Western Art List #7

View Set

Chapter 11 construction and environmental issues

View Set

Chapter 13 Cost Accounting videos and exercises

View Set

ATI RN Maternal Newborn Online Practice 2019 A with NGN

View Set

Qur'an Exam 2 (Final) Study Guide

View Set

Chapter 35: Assessment of Musculoskeletal Function

View Set