
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































Why are functions helpful? - correct answer ✅Functions facilitate code reusability, readability, and maintenance What is "scope" in terms of programming language python? - correct answer ✅Scope is the term used to describe the points at which in code variables and functions are defined. Why is there an error when trying to run this code? a=int(input()) b=int(input()) if c
d. def my_func(a, b, c): - correct answer ✅c Which of the following lines of code will not call a function named "my_func" that has three parameters (a, b, and c) where b defaults to 0 and c defaults to "Yes"? a.) my_func( ) b.) my_func(1, c="No") c.) my_func(1) d.) my_func(1, 2) - correct answer ✅a Which of the following will import a specific function "add_numbers" from a library "adding_library"? - correct answer ✅from adding_library import add_numbers import (How to import the full module/libray) from import < function name > There is a function, "my_function". Within that function, a variable called "my_var" is created. In which namespace does my_var exist? - correct answer ✅local Python's int( ) function will take an argument and convert it to an integer. In which namespace does int( ) exist? - correct answer ✅built-in
Some code is being written where an exception may occur. The exception should be handled properly so the application will not crash. The specific exception that may occur is the ZeroDivisionError exception. Regardless of whether or not the exception occurs, there's some cleanup code that needs to run. What should be done? - correct answer ✅Implement a try block, a specific ZeroDivisionError except block, and a finally block. Which of the following will set my logging level to CRITICAL? - correct answer ✅logging.basicConfig(level = logging.CRITICAL) Why is Python a popular software development language? - correct answer ✅Python has a large community of active developers building libraries and tools for Python development. Python is very concise, meaning you can do more with less code. Python is relatively easy to read. NOT A REASON: (Python code is compiled into an executable, which is helpful for web development.) In which specializations is Python a primary language of choice for professionals and researchers? - correct answer ✅data science/artificial intelligence
The primary function of the python interpreter is to: - correct answer ✅read code, execute it, and return the output One of the benefits of Jupyter Notebook is that it... - correct answer ✅allows developers to combine code, Markup, and raw text in one document JupyterLab uses IPython as... - correct answer ✅the backend interpreter for python code How do you represent a hexadecimal number in python? - correct answer ✅0x What is the result of this equation 80%25? - correct answer ✅ 5 If I have a string "my_string" with the value "Python is so powerful!" how do I substring to get just "is so"? - correct answer ✅my_string[7:12] remember, the string starts with 0, and the number 12, means that it will stop at 11 I want to open and write to a file called "thatfile.txt". If the file does not exist, I want to create it but if it does exist, I want to write at the end of the file, preserving what's already in the file. How do I do that? - correct answer ✅open("thatfile.txt", "a") What is the value of the variable c after the following statement? a=b=c=d=5 - correct answer ✅ 5
else print(3) - correct answer ✅The colons are missing at the end of the else, elif, and if lines. Which of the following will generate a range of numbers from 11 to 99? - correct answer ✅range[11,100] What does this Python expression evaluate to: 8==8 - correct answer ✅True I have a variable called my_var that contains the value 10. What does the statement my_var +=5 do? - correct answer ✅Adds 5 to the current value of my_var, so my_var will contain the value 15 If I use a variable in an if statement before that variable has been created, what error will I likely get? - correct answer ✅NameError I have a variable called my_var that contains the value 10. What does the expression my_var%=4 do? - correct answer ✅Computes the modulus of my_var and 4, which is 2 and assigns that value (2) to my_var I have a set called my_set and I want to add a new value (5) to the set. Which of the following will accomplish that? - correct answer ✅my_set.add(5) What does the "a" mean when used as the mode argument in opening a file? - correct answer ✅Append mode- write at the end of existing data
I have a dictionary, defined as (my_dictionary = {"Age":22, "Name":"Bob"}). Which of the following will retrieve the age from my_dictionary? - correct answer ✅my_dictionary.get("Age") What does the input function do and which data type does it return? - correct answer ✅Prompts the user to input a value. That value is returned as a string. What is the primary benefit of commenting code? How can good and bad comment blocks impact this benefit? - correct answer ✅Commenting code makes it easier to read which can speed up debugging. Good comments will help the programmer understand the code while bad comments will not and may even confuse people, other programmers, manual debugging. Describe tow scenarios in which you might want to use a dictionary as a data type. Specifically, mention how you would use the dictionary (what is to be represented by keys and what is to represented by values). - correct answer ✅Use a dictionary to represent a phone book. The names would be the keys and the phone numbers would be the values. What are the strengths of Python programming language? - correct answer ✅-Free and open source -Large library/database -Large programming community -easy to prototype -readable -interpreted language (codes are processed at runtime without need of comping) -programs can run interactively
libraries and tools for Python development. - correct answer ✅b What is the primary function of the Python interpreter? - correct answer ✅A python interpreter is a computer program that converts each high-level program statement into machine code. An interpreter translates the command that you write out into code that the computer can understand List three reasons why Python is a popular language among educators and learners.
- correct answer ✅-free with a variety of supporting tools -syntax is concise compared to other languages, meaning you can do more with less -easier to read -code resembles everyday english -active developer community that creates resources -interpreted language, can get immediate feedback without having to wait for an application to compile List three reasons why Python is a popular language among professionals. - correct answer ✅-concise syntax ( do more with less) -extremely robust and powerful -popular choice for quickly building working prototypes -language of choice for data science and AI -large amounts of libraries available for Python development in math, statistics, machine learning and deep learning -web development
What is Anaconda? - correct answer ✅Anaconda is a distribution that includes Python and various other tools including SciPy, NumPy, and pandas. What is NumPy? - correct answer ✅An extremely efficient library used for computation on large data sets and multi-dimensional arrays. What is SciPy? - correct answer ✅a library used for scientific computing including linear algebra, interpolation, and signal and image processing What is pandas? - correct answer ✅a library used for data manipulation in numerical tables and time series data What is the relationship of Jupyter to Ipython - correct answer ✅Jupyter evolved from Python What is JupyterLab? - correct answer ✅an integrated development environment that allows developers to organize and develop in multiple documents with code, Markdown, and text alongside terminals and other components What is the Python interpreter? - correct answer ✅a program that reads Python code, translates it into something called byte code, and then executes the code in a Python Virtual machine, returning the output to the user Which of the following is a simple Hello World application in Python? - correct answer ✅print("Hello, World!")
How do we open a file, write to it (at the end, not overwrite), and then close the file? - correct answer ✅my_file=open('my_file', 'a') <--- this file must already exist. my_file.write('I would love for this exam to be over') (<-- will not appear in the file until the file is closed. ) my_file.close() Why do we se variables in python? - correct answer ✅A variable in Python is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Declaring and re-declaring a variable in Python is as easy as writing names and assigning values to it. What is the result of 80%25? - correct answer ✅ 5 How would you put quotes into a string in Python? - correct answer ✅my_string = "this has "quotes"." Or you can use ' ' to open and use " " to add the quotation If I h ave a string "my_string" with the value "Python is so powerful!" how do I substring to get just "is so"? - correct answer ✅my_string[7:12]
I want to open and write to a file called "thatfile.txt". If the file does not exist, I want to create it. If it does exist, I want to write at the end of the file, preserving what's already in the file. How do I do that? - correct answer ✅that_file=open("that_file.txt", "x") that_file=open("that_file.txt", "a") that_file.write('This is a great day!') that_file.close() What are the syntax rules for creating a variable? - correct answer ✅Must start with either a letter or an _ May only include letters, numbers, and _ Should be all lowercase. (Only constants have all UPPERCASE, i.e. gravity.) -words should be separated by an underscore, however if they are not, Python will not mark it as an error. example of incorrect variable: &player_age (starts with something other than a lowercase letter or ) What type of value is 0o42? **- correct answer_** ✅octal What type of value is 42? - correct answer ✅int What type of value is 4 + 2J? - correct answer ✅complex
What is the proper way to add the number 24 as an element to the set that I've named "my_favorite_numbers"? - correct answer ✅my_favorite_numbers.add(24) What is the proper way to add the number 24 at index 3 of the list that I've named "my_favorite_numbers"? - correct answer ✅my_favorite_numbers.insert(3, 24) LOCATION and then what you want to index. First you need to tell it WHERE you want it to go, then WHAT it is. What does "r" do when used with the file open method? - correct answer ✅opens the file in read mode. What is an expression? - correct answer ✅An expression is a combination of literals, operators, variables, and parentheses used to calculate a value. What is a statement? - correct answer ✅An expression sits on the right-hand side of the = sign and is evaluated first, and then the result is assigned to a variable. statement--> (variable name = expression) What is a conditional statement? - correct answer ✅A conditional statement tells a program what to do if a certain condition is met (i.e., evaluates to True). Example: if a<=b: If a is less than or equal to be (condition, True or false)
a*=2. (What to do if True) What numbers are displayed with range(3,9,2)? - correct answer ✅range(3,9,2) start at position 3, ending at the number preceding 9, and in steps of 2 3,5, What is range(7) equivalent to? - correct answer ✅range(0,7,1) 0,1,2,3,4,5, What is range(2,7) equivalent to? - correct answer ✅range(2,7,1) What is a loop statement for? - correct answer ✅iterates a code block until the end of a range syntax: for in for x in range (7): print(x) 0,1,2,3,4,5,
continue elif x > 6: break print(x) 0,1,2,3,5, Iterate the code block with x in range(10) i.e., x runs from0,1,2,...,9.If x is equal to 4, the continue statement skips the remaining codes and continues with the next number in the range i.e. 5. If x is greater than 6, break statement forces the code block to exit. The result of print(x): 0, 1, 2, 3, 5, 6 What is an iterator? - correct answer ✅allows the interpreter to loop through values in lists, sets, tuples, and dictionaries example: my_list = [1, 3, 5, 7] for x in my_list: print(x) What are comprehensions? - correct answer ✅are container objects (i.e. lists, sets, tuple, dictionaries) that are generated from existing container objects. syntax: [ for n in ]
example: my_list = [1, 3, 5, 7] my_new_list = [2n for n in my_list] How do you do a comprehension with a tuple? - correct answer ✅my_tuple= (1, 3, 4, 5) my_new_tuple= tuple(n1 for n in my_tuple) What is the code that will generate a range of numbers from 11 to 99 with increment of 2? - correct answer ✅range(11, 100, 2) Why will the following code not run? my_num = 0 int(input()) if my_num < 0 print('negative') elif my_num > 0 print('positive') else print('zero') - correct answer ✅no : after each if, elif, and else