Python

Ace your homework & exams now with Quizwiz!

If you want to draw a circle 100 pixels wide, what would be the radius of that circle? 50 pixels

50 pixels

A function must return a value. True False

True False

IDLE in the Mac computer system works differently than the IDLE for Windows computer system. True False

True False

To change the appearance of your turtle to a turtle instead a triangle, we use the code a. turtle.face("turtle") b. turtle.type("turtle") c. turtle.appearance("turtle") d. turtle.shape("turtle")

a. turtle.face("turtle") b. turtle.type("turtle") c. turtle.appearance("turtle") d. turtle.shape("turtle")

Each item on a map has a a. variable and constant b. key and value c. parent and child d. index and list

a. variable and constant b. key and value c. parent and child d. index and list

Single line comments use the symbol a. # b. ! c. @ d. //

a. # b. ! c. @ d. //

Which of the following are valid comments? (Select one or more) a. # This is a comment line b. // This is a single line comment c. # Ask the # user to enter# his/her name d. None of these choices

a. # This is a comment line b. // This is a single line comment c. # Ask the # user to enter# his/her name d. None of these choices

myGrade = 95 print ("My grade is ____" ____ myGrade ) a. %s, + b. %, + c. %s, % d. %, %s

a. %s, + b. %, + c. %s, % d. %, %s

def square(x) : x = x * x return x x = 5 square(x) print(x)

a. 0 b. 5 c. 25 d. An error

What is the output of the following expression 8 + 6 / (2 - 1) * 3 / (3 - 2) a. 10.0 b. 14.0 c. 26.0 d. 48.0

a. 10.0 b. 14.0 c. 26.0 d. 48.0

What is the output of the code snippet? def convertToCelsius (f): celsius = 5*(f-32)/9 return celsius fahrenheitTemp = 100 convertToCelsius(fahrenheitTemp) print ("%s degree Fahrenheit = %s degree Celsius" % (fahrenheitTemp, int(celsius))) a. 100 degree Fahrenheit = 38 degree Celsius b. 100 degree Fahrenheit = 37.77 degree Celsius c. An error d. 100 degree Fahrenheit = 37 degree Celsius

a. 100 degree Fahrenheit = 38 degree Celsius b. 100 degree Fahrenheit = 37.77 degree Celsius c. An error d. 100 degree Fahrenheit = 37 degree Celsius

What is the output of the following code snippet? price = 10.00 quantity = 10 taxRate = 0.05 total = price * quantity total = total + total * taxRate print(total) a. 100.0 b. 105.0 c. 200.0 d. 210.0

a. 100.0 b. 105.0 c. 200.0 d. 210.0

Total = 0 score1 = 20 score2 = 19 total = score1 + score2 print(Total) a. 20 b. 19 c. 39 d. 0

a. 20 b. 19 c. 39 d. 0

Assume the user entered 30 for the first number and 45 for the second number running the following code snippet. What will be the output? number1 = input("Enter the first number") number2 = input("Enter the second number") print (number1 + number2) a. 3045 b. 30 c. 45 d. 75

a. 3045 b. 30 c. 45 d. 75

def myMethod(param1, param2) : param1 = param1 + param2 print(param1) value1 = param1 value2 = param1 - param2 return (value1+value2) value1 = 20 value2 = 10 myMethod(value1+value2, value1-value2) print(value1+value2) a. 40 80 b. 20 10 c. 40 30 d. 30 40

a. 40 80 b. 20 10 c. 40 30 d. 30 40

6 = x 4 = y z = x + y / 2 print(z) a. 5 b. 8 c. 10 d. Error message

a. 5 b. 8 c. 10 d. Error message

import turtle t =turtle.Pen() t.forward(100) t.left(90) t.forward(____) t.left(90) t.forward(____) t.left(90) t.forward(60) a. 60, 100 b. 100, 60 c. 90, 90 d. 90, 100

a. 60, 100 b. 100, 60 c. 90, 90 d. 90, 100

import turtle t = turtle.Pen() t.forward(40) t.left(360/___) t.forward(40) t.left(360/___) t.forward(40) t.left(360/___) t.forward(40) t.left(360/___) t.forward(40) t.left(360/___) t.forward(40) t.left(360/___) t.forward(40) t.left(360/___) t.forward(40) a. 9 b. 5 c. 8 d. 40

a. 9 b. 5 c. 8 d. 40

You want to write a MacBook class to model your Apple computer. What would be the ideal candidates for the methods of your MacBook class? a. screenSize b. price c. turnOn d. shutdown

a. screenSize b. price c. turnOn d. shutdown

A function is a a. set of commands that we can reuse b. variable that we use multiple times c. set of statements to do a specific task d. set of modules

a. set of commands that we can reuse b. variable that we use multiple times c. set of statements to do a specific task d. set of modules

A string can contain: a. space character b. Python reserved keywords c. Numbers d. Symbols

a. space character b. Python reserved keywords c. Numbers d. Symbols

You want to write a Camera class to model a real-life camera. What would be the ideal candidates for the attributes (instance variables) of your camera class? (select all that apply)

a. takePicture b. brand c. chargeCamera d. battery

import turtle t = turtle.Pen() t.forward(40) t.left(90) t.forward(40) t.right(90) t.forward(40) t.left(90) t.forward(40) t.right(90) t.forward(40) t.left(90) t.forward(40) t.right(90) t.forward(40) a. triangle b. square c. circle d. steps

a. triangle b. square c. circle d. steps

Which one of the following choices is a valid Python statement? a. x + y = 18 b. x - y = 6 c. x / y = 2 d. xy = 72

a. x + y = 18 b. x - y = 6 c. x / y = 2 d. xy = 72

x = 'a' y = 'b' temp = x x = y y = temp print("x = %s" % 'x') print("y = %s" % 'y') a. x = b y = a b. x = a y = b c. x = x y = y d. x = b y = temp

a. x = b y = a b. x = a y = b c. x = x y = y d. x = b y = temp

What is not true in object-oriented programming? (Select one or more) a. A class is a custom data type b. We can create many objects from a class c. An object is an instantiation of the class d. Two objects from a class can have different data types

a. A class is a custom data type b. We can create many objects from a class c. An object is an instantiation of the class d. Two objects from a class can have different data types

Which of the following are not true for programming comments? a. A comment is for giving yourself or other programmers information about the code b. Comment don't interfere with the program running. c. Program without comments runs faster than the program with comments. d. Program without comments is relatively harder to understand than the program with comments.

a. A comment is for giving yourself or other programmers information about the code b. Comment don't interfere with the program running. c. Program without comments runs faster than the program with comments. d. Program without comments is relatively harder to understand than the program with comments.

Which of the following are not true for a variable name? (select one or more) a. A variable name can't start with a number b. A variable name can't have a space c. A variable name must start with a letter d. After the first letter, the rest of the variable name can contain any character

a. A variable name can't start with a number b. A variable name can't have a space c. A variable name must start with a letter d. After the first letter, the rest of the variable name can contain any character

Assume there is no file called "datafile.txt" in the folder where we have saved the following code snippet. What will happen if we run the following code? myFile = open("datafile.txt") myContent = myFile.readlines() print(myContent) myFile.close() a. An error message saying "No such file or directory: 'datafile.txt'". b. The program will run without any error. No file will be created in that folder c. The program will run without any error but a file named datafile.txt will be created in that folder d. There program will not run and will not display an error.

a. An error message saying "No such file or directory: 'datafile.txt'". b. The program will run without any error. No file will be created in that folder c. The program will run without any error but a file named datafile.txt will be created in that folder d. There program will not run and will not display an error.

To write code in a new file using IDLE, we go to a. File and then Save... b. File and then New File c. Run and Run Module d. File and then Open...

a. File and then Save... b. File and then New File c. Run and Run Module d. File and then Open...

score = 90 if score < 60: print('Grade is F') elif score > 60: print('Grade is D') elif score > 70: print('Grade is C') elif score > 80: print('Grade is B') elif score > 90: print('Grade is A') elif score > 98: print('Grade is A+') else: print('Invalid score')

a. Grade is D b. Grade is A c. Grade is A+ d. Invalid score

name = "John" print ("Hello Mr. %s!' % name) a. Hello Mr. John! b. "Hello Mr. John!" c. Hello Mr. name d. An error

a. Hello Mr. John! b. "Hello Mr. John!" c. Hello Mr. name d. An error

What is the output of the following code snippet? income = 75000 if income > 75000: print('High') elif income < 75000 and income > 25000: print('Medium') elif income < 25000 and income > 0: print('Low') else: print('No income') a. High b. Medium c. Low d. No income

a. High b. Medium c. Low d. No income

'IDLE' - stands for a. Ideal Development Learning Editor b. Integrated DeveLopment Editor c. Integrated DeveLopment Environment d. Internet DeveLopment Environment

a. Ideal Development Learning Editor b. Integrated DeveLopment Editor c. Integrated DeveLopment Environment d. Internet DeveLopment Environment

for count in range(0,2): for counter in range(1,3): print("Nested Loop") a. Nested Loop Nested Loop b. Nested Loop Nested Loop Nested Loop c. Nested Loop Nested Loop Nested Loop Nested Loop d. Nested Loop Nested Loop Nested Loop Nested Loop Nested Loop

a. Nested Loop Nested Loop b. Nested Loop Nested Loop Nested Loop c. Nested Loop Nested Loop Nested Loop Nested Loop d. Nested Loop Nested Loop Nested Loop Nested Loop Nested Loop

Which statement will print "Hello World!" as your program output? a. Print("Hello World!") b. print["Hello World!"] c. print("Hello World!") d. display('Hello World')

a. Print("Hello World!") b. print["Hello World!"] c. print("Hello World!") d. display('Hello World')

________ is a Python library that helps with math, science and engineering research. a. PyGame b. SciPy c. SciMath d. Turtle

a. PyGame b. SciPy c. SciMath d. Turtle

What will be the output for the following code snippet? number1 = 8 number2 = 5 print("Sum is " % str(number1 + number2)) a. Sum is 13 b. Sum is 85 c. Sum is number1+number2 d. An error

a. Sum is 13 b. Sum is 85 c. Sum is number1+number2 d. An error

Select the false statements. (Select one or more) a. Super or parent class inherits everything from the sub or child class b. A child class is a more generalized form of super class c. Relationship between classes in inheritance is called a "IS A" relationship d. We can reuse code using inheritance

a. Super or parent class inherits everything from the sub or child class b. A child class is a more generalized form of super class c. Relationship between classes in inheritance is called a "IS A" relationship d. We can reuse code using inheritance

courseName = input("Enter Course Name ") testScore = input('Enter test score ') quizScore = input('''Enter quiz score ''') assignmentScore = input("Enter assignment score") totalScore = int(testScore) + int(quizScore) + int(assignmentScore) print("Total score is %s" % totalScore) comment = '''Great job in %s Happy coding''' print(comment % courseName) a. The program will run by showing correct output b. The program will not run. It will show an error message c. The program will run by showing wrong output d. The program will run but will not show any output

a. The program will run by showing correct output b. The program will not run. It will show an error message c. The program will run by showing wrong output d. The program will run but will not show any output

You wanted to printout the following text I don't like coffee Which of following code snippets will let you do so? (select one or more) a. print('I don't like coffee') b. print(#I don't like coffee#) c. print('I don\'t like coffee') d. print('''I don't like coffee''')

a. print('I don't like coffee') b. print(#I don't like coffee#) c. print('I don\'t like coffee') d. print('''I don't like coffee''')

Which of the following statements are true about reset() and clear() functions in turtle? (Select one or more) a. There is no difference between reset() and clear() functions b. reset() function does not clear the lines but clear() function does c. both reset() and clear() functions clear the lines d. reset() function moves the turtle back to center of the screen but clear() function does not

a. There is no difference between reset() and clear() functions b. reset() function does not clear the lines but clear() function does c. both reset() and clear() functions clear the lines d. reset() function moves the turtle back to center of the screen but clear() function does not

Indentation improves code readability. It is done using: a. Whitespace b. Curly braces c. Square brackets d. Round brackets

a. Whitespace b. Curly braces c. Square brackets d. Round brackets

brave = False strong = True if brave or strong: print('You are brave') elif strong or brave: print('You are strong') else: print('You are neither brave nor strong') a. You are brave b. You are strong c. You are braveYou are strong d. You are neither brave nor strong

a. You are brave b. You are strong c. You are braveYou are strong d. You are neither brave nor strong

Which of the following are invalid variable names? (Select one or more) a. _____2_x b. 6Type c. _$ d. this_is_a_very_detailed_variable_name

a. _____2_x b. 6Type c. _$ d. this_is_a_very_detailed_variable_name

a = 20 b = 15 if b < a : a = a - b if a < b : b = a + b print('a = %s b = %s' % (a, b)) a. a = 5 b = 15 b. a = 20 b = 15 c. a = 5 b = 20 d. An error

a. a = 5 b = 15 b. a = 20 b = 15 c. a = 5 b = 20 d. An error

Using Python, you can (select one or more) a. create a virtual reality game b. do scientific research c. support C++ and Java programming Language d. create a new programming language

a. create a virtual reality game b. do scientific research c. support C++ and Java programming Language d. create a new programming language

To draw a dashed line, which of the following turtle functions would we NOT need to use? (Select one or more) a. dashedline() b. penup() c. right() d. pendown()

a. dashedline() b. penup() c. right() d. pendown()

Which of the following statement(s) will let us write to a file named data.txt. Assume the file is saved in the same folder where the Python program file is saved. (Select one or more) a. datafile = open("data.txt") b. datafile = open("data.txt", "w") c. datafile = open("data.txt", "a") d. all of the above

a. datafile = open("data.txt") b. datafile = open("data.txt", "w") c. datafile = open("data.txt", "a") d. all of the above

Which of the following statements will let us read the content from a file named data.txt? Assume the file is saved in the same folder where the Python program file is saved. a. datafile = open("data.txt") b. datafile = open("data.txt", "w") c. datafile = open("data.txt", "a") d. all of the above

a. datafile = open("data.txt") b. datafile = open("data.txt", "w") c. datafile = open("data.txt", "a") d. all of the above

Review the following Python program. Which lines contain errors? a. def calculateAreaOfTriangle(b, h) b. area = (b*h)/2 c. return area d. e. base = 10 f. height = 6 g. area = calculateAreaOfTriangle(base, height) h. print("Area of the triangle %s" % area)

a. def calculateAreaOfTriangle(b, h) b. area = (b*h)/2 c. return area d. e. base = 10 f. height = 6 g. area = calculateAreaOfTriangle(base, height) h. print("Area of the triangle %s" % area)

Consider a class called Product that has a class variable called idNumber. We created an object called myProduct from the Product class. Which of the following is incorrect for the class variable idNumber? a. idNumber is shared by all Product objects b. myProduct.idNumber = myProduct.idNumber + 1 c. Product.idNumber = Product.idNumber + 1 d. print(myProduct.idNumber)

a. idNumber is shared by all Product objects b. myProduct.idNumber = myProduct.idNumber + 1 c. Product.idNumber = Product.idNumber + 1 d. print(myProduct.idNumber)

Identify the line(s) with errors. a. import turtle b. t = turtle.pen() c. t.circle() d. t.penup() e. t.left(90) f. t.forward(100) g. t.pendown() h. t.pencolor(blue) i. t.forward(40) j. t.left(120) k. t.forward(40) l. t.left(120) m. t.forward(40)

a. import turtle b. t = turtle.pen() c. t.circle() d. t.penup() e. t.left(90) f. t.forward(100) g. t.pendown() h. t.pencolor(blue) i. t.forward(40) j. t.left(120) k. t.forward(40) l. t.left(120) m. t.forward(40)

Debug the following program. Which of the lines have errors? a. item = 'Pen' b. if item = 'Pencil': c. cost = 0.99 d. else if item == 'Pen': e. cost = 1.99 f. else g. cost = 0.0 h. print('Item %s costs %s' % (item, cost))

a. item = 'Pen' b. if item = 'Pencil': c. cost = 0.99 d. else if item == 'Pen': e. cost = 1.99 f. else g. cost = 0.0 h. print('Item %s costs %s' % (item, cost))

Your friend Mike has his favorite movie list called MikesList. He gave you his list and you want to add that into your movieList. What will be the correct way to add MikesList into your movieList? a. movieList = movieList + MikesList b. movieList.add(MikesList) c. movieList.join(MikesList) d. movieList.insert(MikesList)

a. movieList = movieList + MikesList b. movieList.add(MikesList) c. movieList.join(MikesList) d. movieList.insert(MikesList)

Fill in the blanks. def convertToMeter(feet) : meter = feet * 0.3048 return meter ft = 9 __________________ print("%s feet = %s meter" % (ft, mt)) a. mt = convertToMeter(ft) b. ft = convertToMeter(mt) c. mt = return meter d. mt = %s meter

a. mt = convertToMeter(ft) b. ft = convertToMeter(mt) c. mt = return meter d. mt = %s meter

What is the missing statement to draw a circle with radius 30? Import turtle p = turtle.Pen() ____________ a. p.circle (15) b. 30.circle() c. circle(30) d. p.circle(30)

a. p.circle (15) b. 30.circle() c. circle(30) d. p.circle(30)

An if statement evaluates a(n) _________ statement a. parameter b. conditional c. error d. argument

a. parameter b. conditional c. error d. argument

The number unit that we use to move our turtle is called _______ a. point b. pixel c. photon d. inch

a. point b. pixel c. photon d. inch


Related study sets

Penny Ch 16-Anatomy of the Female Pelvis

View Set

Standard 4.4 Through 4.6 Review For Unit Test

View Set

Chapter 8: Subnetting IP Networks

View Set

Phasmophobia ghost traits/abilities quiz

View Set

Ecnomoics for Managers- Creating Markets

View Set