Skill Check Quiz Questions s364

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

argument

a value provided to a function when the function is called. This value is assigned to the corresponding parameter in the function.

parameter

a variable used inside a function to hold the value passed in as an argument

What will be the output of the following code? d = {"Christine" : 20, "Kevin" : 19} "Christine" in d

True

Which of the following can execute code cells in Jupyter notebook? (select ALL correct answers)

control+enter and command+ enter(mac), shift +enter, from the menu cell - run cells

A function is defined like below. Which of the following function call will lead to most senseless result (even though the code would not err out)? def greeting(name, time="Day ", salute='Ms. '): str = "Good " + time + salute + name return str

greeting('John','Mr. ')

A function is defined like below. Which of the following function call will lead to an execution error? def greeting(name, time="Day ", salute='Ms. '): str = "Good " + time + salute + name return str

greeting(salute='Mr.', time='Evening')

which of the following variable name is vaild in python

three_dots

For sequential access of a file, what of the following is true? Read the file from beginning to end, cannot skip ahead [ Select ] ["False", "True"] Read any piece of data anywhere you want [ Select ] ["True", "False"] Once a piece of data is read, cannot read it again using read() [ Select ] ["True", "False"] Data can be read repeatedly in one read() call [ Select ] ["True", "False"]

true, false, true, false

For the following code future_day = date(3089, 1, 1) future_day.weekday() You get 1 as the returned value. Which week day is this future day?

Tuesday

set

a collection of unordered items with unique values

time

contains the time information including hour, minute, or second

I can use from datetime import date, time, datetime, timedelta dt_now = datetime.now() to get the current time. What of the following is correct?

I can get the datetime of 5 hours before now by doing dt_now + timedelta(hours=-5)

where in the computer is a variable such as "x" stored after the following Python line finished? x=123

main memory

You have a string str = "IU has over 40000 students"; str.isdigit() str.isalpha() str.isalnum() Which of the above method will return true and why?

none of the above will return true since it contains a combination of alphabetic characters, numbers and spaces

exception handling

purposefully designed code executed when unexpected problem occurs in normal execution

Given list1 = ["H","e", "l", "l", "o"] what does "&".join(list1) do?

return a string: "H&e&l&l&o"

When open a file to write to it, we need to pass an argument to the mode parameter, what value should we pass to mode?

w

floating point

A type that represents numbers with fractional parts.

Which of the following operator in Python joins strings together? For example: "Hello " operator "World!" result in "Hello World!"

+

return value

The result of a function passed back to the caller

dot notation

The syntax for calling a function in another module by specifying the module name followed by a dot (period) and the function name.

Which of the following is NOT true about if statement?

an if statement must be matches with an else branch

value

an object that appears in a dictionary as the sescond part of a key-value pair.

modulus operator

an operator, denoted with a percent sign (%), that works on integers and yields the remainder when one number is divided by another

You have the following code: fruit_list = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] fruit_list.remove('apple') fruit_list.remove('orange') fruit_list[0] = 'watermelon' fruit_list[-2] = 'pineapple' if len(fruit_list) < 3:print("You have too few types of fruits")elif len(fruit_list) <= 5:print("You are doing OK")else:print("You have great fruit diversity") What will you get?

You are doing OK

What will be the output of following code? list2 = ["one", "two", [1, 2, 3, 4], [1.5, True, "23"]] list2[3][1] = 9 print(list2)

["one", "two", [1, 2, 3, 4], [1.5, 9, "23"]]

For the following list: lst = [9, 18, -1, -31, 15] create a list that identifies each element as positive or negative. Which of the following is correct? (You can ignore the possibility of having 0 in the list.)

["positive" if ele > 0 else 'negative' for ele in lst]

Which of the following are advantages of using Jupyter notebook?

code development, documentation, communicate and share results

f you accidentally deleted (cut) a cell and want to get it back, what can you do? In the _______ mode, use the keyboard shortcut ________ .

command, z

To be executed, which of the following does Python programming language use?

interpreter

which of the following is correct about Python

it is a high-level language

to determine the length of a string that's in a variable named city, you can use this code

len(city)

function

pre-defined code module executed when needed

the following code will cause an error Print("Hello world!")

true

When executing the following code, what error would be raised? x=4 x+ "USA"

type error, because x is an integer and "USA" is a string, the data types are different

What data type does the value 5.3 have?

float

what of the following is true of the following code x="4" x=float(x)

after the execution x now contains 4.0

assignment

A statement that assigns a value to a variable.

function definition

A statement that creates a new function, specifying its name, parameters, and the statements it executes.

tuple

An immutable data structure with a sequence of elements.

key

An object that appears in a dictionary as the first part of a key-value pair.

You have a dictionary: cars = {'Honda': ['Accord', 'Civic', 'CR-V', 'Fit'], 'Toyota': ['Camery', 'Corolla', 'Prius', 'Avalon'], 'Ford': ['Focus', 'Mustang', 'Ranger', 'Galaxy']} Which of the following code can get you the first 2 cars of Toyota?

cars['Toyota'][0:2]

A function is defined like below. Which of the following function call generates an error? def greeting(name, time="Day ", salute='Ms. '): str = "Good " + time + salute + name return str

call the function by passing in 0 argument

loop

execute certain code repeatedly for multiple number of times

Which of the following code can work successfully and have a dictionary created? set1 = {1, 2} set2 = {1, 3} d = {set1:{3:4}, set2:{4:5}}

d={(1,2):[3,4],(2,3):[9,8]}

We use strptime() to convert string to a datetime object. Which of the following code does the proper conversion for the following date string: from datetime import date, time, datetime, timedelta date_string = 'Wednesday, December 30, 2020 10:33'

datetime.strptime(date_string, '%A, %B %d, %Y %H:%M')

what do you get when you run the code 1. int(True) 2. int(False) 3. int(None)

1. 1 2. 0 3. TypeError

You have the following dictionary student = { "name": "Emma", "class": "S364", "grade": "A" } What of the following are correct ways to remove key "grade" and its value? Select Yes for Correct one(s) and No otherwise. 1. student.remove('grade') 2. del student["grade"] 3. student.pop('grade') 4. student['grade']=None

1. no 2. yes 3. yes 4. no

To access the first three characters in a string that's stored in a variable named message, you can use which of the following statement? Mark True if a statement can be used. 1. first_three = message[0:3] 2. first_three = message[1:3] 3. first_three = message.slice(0:2) 4. first_three = message[:3]

1. true 2. false 3. false 4. true

You have 3 people's age stored in 3 variables first, second and third. If their ages are all different, will the following statement find find the oldest age properly? 1. if first > second and first > third: print("Oldest age is", first) elif second > first and second > third: print("Oldest age is", second) else: print("Oldest age is", third) 2. if first > second and second > third: print("Oldest age is",first) elif second > first and first > third: print("Oldest age is",second) elif third > first and first > second: print("Oldest age is",third) else: print("Cannot tell") 3. if first > second or first > third: print("Oldest age is",first) elif second > first or second > third: print("Oldest age is",second) else: print("Oldest age is",third)

1. yes 2. no 3. no

Take a look at the following code: for i in range(1, 7, 3): print("Hello world!") How many times Hello world! will be printed out?

2

what do you get from the following code 10/5

2.0

What is the result of the following code: num = 3 while num > 0: print(num) num = num - 1

3 2 1

What is the result of the following code: num = 3 while num > 0: print(num)

3 3 3 ... won't stop

what will x be after the code is executed (execute it in Juypter notebook to be sure) x=43 x=x+1

44

list

a mutable data structure with a sequence of elements

Take a look at the following code: for i in range(1, 7, -3): print("Hello world!") How many times Hello world! will be printed out?

0

what is the result of 10%3

1

void function

A function that doesn't return a value.

dictionary

A mapping from a set of keys to their corresponding values. unsorted elements

statement

A section of code that represents a command or action. So far, the statements we have seen are assignments and print expression statement.

function call

A statement that executes a function. It consists of the function name followed by an argument list in ()

import statement

A statement that reads a module file and make the module functions available

item

Another name for a key-value pair.

You have the following code: str1 = 'I love Python' str1.replace('I', 'We') print(str1) What do you get and why.

I love Python because the replace does not change the string stored in variable str1. String has a property of immutable

You have the following code: your_age = input("enter your age: ") friend_age = input("enter your friend's age: ") if your_age > friend_age: print('You are older than your friend') elif your_age < friend_age: print('You are younger than your friend') else: print("You two are of the same age") If your age is entered as 9 and your friend's age is entered as 11, what would be the output of this program and why?

Output: You are older than your friend. This not right because Python compare "9" and "11" as two strings. Only the first character is compared in this case and "9" comes after "1" in Unicode values.

What is the output if the user types in "secret"? password = input("Please enter your password\n") while password != 'secret': print("Try again") password = input() print("Welcome!")

Welcome!

You have the following code: fruit_list = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] fruit_list.remove('apple') fruit_list.remove('orange') fruit_list[0] = 'watermelon' fruit_list[-2] = 'pineapple' print(fruit_list) What will you get?

['watermelon', 'cherry', 'kiwi', 'pineapple', 'mango']

What will be the output of the following code: list1=[4, 10, 7] list2=list1*2 print(list2)

[4,10,7,4,10,7]

When would you use a markdown cell? (select ALL correct answers)

add a title to a jupyter notebook, add headings to sections of a jupyter notebook

conditional

at a decision point, the code execution could go through different branches that are mutually exclusive

datetime

contains complete date and time information including year, month, day, hour, minute, and second

date

contains the date information including year, month, and day

timedelta

contains time interval or duration information. the difference between two dates or times

The following sentences try to describe the control flow of try/except structure. Which ones are INCORRECT ? Program always executes the code inside try block then the code inside except block and execution continues after the try/except structure [ Select ] ["Incorrect", "Correct"] When the code executes without any exception, the code block inside try is executed and code inside except is skipped and program continues after the try/except structure [ Select ] ["Correct", "Incorrect"] When the code execution encounters an exception, the code inside the try block after the line of code that encounters the error is skipped, code inside except is executed and programs continue after the try/except structure [ Select ] ["Incorrect", "Correct"] When the code execution encounters an exception, the code block inside try is skipped, code inside except is executed and programs stops execution after except [ Select ] ["Incorrect", "Correct"]

correct, correct, correct, incorrect

Which keyword indicates the start of the function definition?

def

You have a multiple level nested dictionary: department= { "class":{ "student":{ "name":"Ashley", "grade":{ "A100":"A-", "K201":"B+" } } } } Which of the following can get the grade of K201

department['class']['student']['grade']['K201']

What are the reasons to use comments in code? Select ALL correct answers.

describe or explain the code logic, provide information such as the author, version, date of the code, hide some code from the interpreter so they won't be executed

dict = {'a': 768, 'b' : 98, 'c': 45, 'd': 165}

dict['b']

What is the output of the following code? tuple1=(5,1,7,2,2) tuple1.remove(2) print(tuple1)

error

sequential

execute the code line by line in the order it is written

Python code is always executed from the top to the bottom without any exceptions

false

Which of the following situations are good candidates to be handled in a try/except structure? Select True if it is. Might misspell the name of the function called [ Select ] ["True", "False"] Missing colon (:) after the for loop header [ Select ] ["True", "False"] Ask the user to enter a number which will be converted to a float in the program [ Select ] ["False", "True"] Try to open a file with a user provided file path [ Select ] ["True", "False"]

false, false, true, true

If you have the following code fruit_list = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] Which of the following code will allow you to retrieve kiwi and melon in a list? (Select ALL that works).

fruit_list[-3:-1] fruit_list[4:6]

If you have the following code: fruit_list = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] Which of the following code will allow you retrieve orange? (Select ALL that works). It is recommended that you use Jupyter notebook to try it out before submitting your answer.

fruit_list[3] fruit_list[-4]

A school has following rules for grading system: Below 25 - F 25 to 45 - E 46 to 50 - D 51 to 60 - C 61 to 80 - B Above 80 - A Which of the following is an INCORRECT implementation?

if marks<25: print ("F") elif marks>=25 and marks<45: print("E") elif marks>=46 and marks<50: print("D") elif marks>=51 and marks<60: print("C") elif marks>=61 and marks<=80: print("B") else: print("A")

Which of the following comparison between lists and tuples are correct? Select ALL correct answers.

lists use brackets ([]) as the boundaries of the items and tuples use parentheses as the boundaries of the items, processing tuples is faster than processing lists

If you have a string string = 'I love Python' Which of the following will result in an error?

string[44]

You have the following 3 sets set1 = {10, 20, 30, 40, 50} set2 = {30, 40, 50, 60, 70} set3 = {10, 50} Which of the following is true

set 1 > set 3 and set 3 is a subset of set 1

You have the following 2 sets set1 = {10, 20, 30, 40, 50} set2 = {30, 40, 50, 60, 70} Which of the following code will get you a set of all values in set1 but not in set2 and in set 2 but not in set1? In other words, find a set of values that are not in both set1 and set2.

set1.symmetrict_difference(set2)

You have the following 2 sets set1 = {10, 20, 30, 40, 50} set2 = {30, 40, 50, 60, 70} Which of the following code will get you a set of all values found in set1 and set2 (even though they might not be in both)? Select ALL correct ones

set1.union(set2) set1|set2

What is the function of the secondary storage in a computer?

store information for the long term, even beyond a power cycle


Ensembles d'études connexes

Individual Health Insurance Policy General Provision

View Set

Medical-surgical: gastrointestinal

View Set

WITHDRAWAL SYMPTOMS: Substance Abuse

View Set

Node.js Interview Questions - Advanced Level

View Set