Docsity

WGU D335 Introduction to Programming in Python LATE, Exams of Nursing

Toggle sidebar
bg1
WGU D335 Introduction to Programming in
Python –Real Study Guide – WGU – 2026/2027 |
Fully solved Exam
How are most Python programs developed?
Writing code in files - The Python interpreter can load and execute Python code
saved in files
string literal
text enclosed in quotes, may have letters, numbers, spaces , or symbols.
Given the variable num_cars = 9, which statement prints 9?
print(num_cars)
newline character
"\n" moves output to the next line
Whitspace
Any space, tab or newline
Input function
Causes the interpreter to wait until the user has entered some text and has
pushed the return key
string
It simply represents a sequence of characters.
Which statement reads a user-entered string into variable num_cars?
num_cars = input ()
Type
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download WGU D335 Introduction to Programming in Python LATE and more Exams Nursing in PDF only on Docsity!

WGU D335 Introduction to Programming in

Python – Real Study Guide – WGU – 2026/2027 |

Fully solved Exam

How are most Python programs developed? Writing code in files - The Python interpreter can load and execute Python code saved in files string literal text enclosed in quotes, may have letters, numbers, spaces , or symbols. Given the variable num_cars = 9, which statement prints 9? print(num_cars) newline character "\n" moves output to the next line Whitspace Any space, tab or newline Input function Causes the interpreter to wait until the user has entered some text and has pushed the return key string It simply represents a sequence of characters. Which statement reads a user-entered string into variable num_cars? num_cars = input () Type

Determines how a value can behave. For example, integers can be divided by 2, but not strings ex 'Hello' int function can be used to convert that string to the integer for numbers Type a statement that converts the string '15' to an integer and assigns my_var with the result. my_var = int('15") syntax error An error that results when an instruction does not follow the syntax rules or grammar of the programming language. Runtime error An error that occurs when the program is run using certain sets of data that result in some illegal operation, such as dividing by zero. Crash runtime error halts the execution of the program. Abrupt and unintended termination of a program logic error errors may be subtle enough to silently misbehave, instead of causing a runtime error and a crash. An example might be if a programmer accidentally typed "2 4" rather than "2 40" - the program would load correctly, but would not behave as intended Bug Is also called logic error Integrated Development Environment (IDE) Provides a developer with a way to create a program, run the program, and debug the program all within one application.

the process of associating names with interpreter objects Properties of objects Python object has three defining properties: value, type, and identity. Identity A unique identifier that describes the object. Mutability indicates whether the object's value is allowed to be changed Immutable unchangeable such as integers and strings Id() that gives the value of an object's identity floating point numbers Numbers where the decimal point can float because there is no fixed number of digits before and after the decimal point. AKA: real numbers The number of cars in a parking lot. int The current temperature in Celsius. float A person's height in centimeters. float The number of hairs on a person's head. int The average number of kids per household.

int Which of the following arguments completes print() to output two digits after the decimal point?print(f'{(7.0 / 3.0)_____) print(f'{(7.0/3.0):.2f}') outputs 2.33. What is output by print(f'{0.125:.1f}')? print(f'{0.125:.1f}') outputs the value with one digit after the decimal point. What is output by print(f'{9.1357:.3f}')? print(f'{9.1357:.3f}') outputs 9.136 because the third digit after the decimal point is rounded. ( ) Items within parentheses are evaluated first. In 2 * (x + 1), the x + 1 is evaluated first, with the result then multiplied by 2. **exponent ****

  • used for exponent is next. In xy 3, x to the power of y is computed first, with the results then multiplied by 3. unary -
  • used for negation (unary minus) is next. In 2 * -x, the -x is computed first, with the result then multiplied by 2. The floor division operator // can be used to round down the result of a floating-point division to the closest smaller whole number value. modulo operator (%) evaluates the remainder of the division of two integer operands. Ex: 23 % 10 is

Given a non-negative number x, which expression has the range 5 to 10?

[ ], grouping symbols, A pair of symbols used to enclose sections of an expression. What character is in index 2 of the string "America"? The first character "A" has index 0, "m" has index 1, and index 2 is "e". Write an expression that accesses the first character of the string my_country. my_country[0] Assign my_var with the last character in my_str. Use a negative index my_var = my_str[-1] String concatenation A program can add new characters to the end of a string in a process Container A construct used to group related values together and contains references to other objects instead of data List A container created by surrounding a sequence of variables or literals with brackets [ ]. Ex: my_list = [10, 'abc'] creates a new list variable my_list that contains the two items: 10 and 'abc' Element A list of item Element's Index A list is also a sequence, meaning the contained elements are ordered by position in the list Write a statement that creates a list called my_nums, containing the elements 5, 10, and 20.

my_nums = [5, 10, 20] Write a statement that creates a list called my_list with the elements - and the string 'lists are fun'. my_list = [-100, 'lists are fun'] Write a statement that creates an empty list called class_grades. class_grades = [] Lists Are useful for reducing the number of variables in a program. Instead of having a separate variable for the name of every student in a class, or for every word in an email, a single list can store an entire collection of related variables. Write a statement that assigns my_var with the 3rd element of my_list. my_var = my_list[2] Write a statement that assigns the 2nd element of my_towns with 'Detroit'. my_towns[1] = 'Detroit' Method instructs an object to perform some action, and is executed by specifying the method name following a "." symbol and an object. append() list method is used to add new elements to a list. Elements can be removed using pop() or remove() methods Update the price of the second item in house_prices to '$175,000'. house_prices[1] = '$175,000' Add a price to the end of the list with a value of '$1,000,000'.

Create a new named tuple Dog that has the attributes name, breed, and color. Dog = namedtuple('Dog', ['name', 'breed', 'color']) Let Address = namedtuple('Address', ['street', 'city', 'country']). Create a new address object house where house.street is "221B Baker Street", house.city is "London", and house.country is "England". house = Address('221B Baker Street', 'London', 'England') Given the following named tuple Car = namedtuple('Car', ['make', 'model', 'price', 'horsepower', 'seats']), and data objects car1 and car2, write an expression that computes the sum of the price of both cars. car1.price + car2.price Add the literal 'Ryder' to the set names. names.add('Ryder') Add all of the elements of set goblins into set monsters. Remove all of the elements from the trolls set. trolls.clear() set.intersection Returns a new set containing only the elements in common between set and all provided sets. set.union Returns a new set containing all of the unique elements in all sets. set.difference Returns a set containing only the elements of set that are not found in any of the provided sets. set_a.symmetric_difference

Returns a set containing only elements that appear in exactly one of set_a or set_b Use braces to create a dictionary called ages that maps the names 'Bob' and 'Frank' to their ages, 27 and 75, respectively. For this exercise, make 'Bob' the first entry in the dict. {'Bob': 27, 'Frank': 75} A dictionary entry is accessed by placing a key in curly braces { }. A key is placed in brackets [ ] to access a specific dictionary entry. Curly braces { } are used to build a dictionary. Dictionary entries are ordered by position. As of Python 3.7, the standard is for dictionaries to maintain their left-right insertion order. Though ordered, dictionary entries cannot be accessed by indexing. Which statement adds 'pears' to the following dictionary? prices['pears'] = 1. Sequence types string, list, and tuple are all containers for collections of objects ordered by position in the sequence, where the first object has an index of 0 and subsequent elements have indices 1, 2, etc. Mapping type Only in Python is the dict type. Like a sequence type, a dict serves as a container. The list ['a', 'b', 3] is invalid because the list contains a mix of strings and integers. False. Lists can contain mixes of types. A sorted collection of integers might best be contained in a list.

3 tacos cost 3. print(f'{num_items} tacos cost {cost_taco * num_items}') A replacement field can contain almost any expression, including multiplication of two variables to calculate the total cost. Format specifications inside a replacement field allows a value's formatting in the string to be customized. A format specification is introduced with a colon : presentation type is a part of a format specification that determines how to represent a value in text form, such as integer (4), floating point (4.0), fixed precision decimal (4.000), percentage (4%), binary (100), etc. branch a sequence of statements only executed under a certain condition. if branch A branch taken only if an expression is true. If-else branches has two branches: The first branch is executed IF an expression is true, ELSE the other branch is executed. If-elseif-else branches Commonly a programmer wishes to take one of multiple (three or more) branches. An if-else can be extended to an if-elseif-else structure. Each branch's expression is checked in sequence; as soon as one branch's expression is found to be true, that branch is taken. If no expression is found true, execution will reach the else branch, which then executes. Boolean

a type that has just two values: True or False. inequality operator (!=) evaluates to true if the left and right sides are not equal, or different. If user_age equals 62, assign item_discount with 15. Else, assign item_discount with 0. if user_age == 62: item_discount = 15 else: item_discount = 0 If num_people equals 10, execute group_size = 2 group_size. Otherwise, execute group_size = 3 group_size and num_people = num_people - 1. if num_people == 10: group_size = 2 * group_size else: group_size = 3 * group_size num_people = num_people - 1 If num_players does not equal 11, execute team_size = 11. Otherwise, execute team_size = num_players. Then, no matter the value of num_players, execute team_size = 2 * team_size. if num_players != 11: team_size = 11 else: team_size = num_players team_size = 2 * team_size x is less than y but greater than z. Z A learning method involving video lectures at home and labs in class Reverse Course Input-Process-Output thinking standard to determine coding structure IPO thinking standard A special variable in Python that holds the name of the current module name A special variable in Python that indicates the main module main A resource for learning Python programming Python Crash Course Book  Application Programming Interfaces accessible to the public Public API's Time management method using a timer to break work into intervals Pomodoro Technique Data structure with key-value pairs used for mapping inputs to outputs Dictionaries An introductory course to computer science offered by Harvard University CS An efficient, comparison-based sorting algorithm Merge Sort Ordered collection of items in Python denoted by square brackets Lists

Immutable ordered collection of items in Python denoted by parentheses Tuples Symbols used to represent values and perform operations Variables and Expressions Blocks of organized, reusable code for specific tasks Functions Guided demonstrations of critical programming exercises Lab Walkthroughs Symbols used to perform mathematical operations in Python Arithmetic Operators Operations that return true or false based on the comparison of values Comparisons Increasing the value of a variable by a specified amount Incrementing Function to obtain the magnitude of an integer, removing the negative sign Absolute value function Function to round a value to a specified number of digits after the decimal point Round function Statements used for repeated execution of instructions in a program Iteration Statements An educational coding platform for honing programming skills Codewars

An ordered and unchangeable collection in Python, allowing duplicates and faster operations Tuple Unable to be changed, e.g., tuple elements Immutable Dividing integers to get the whole number part of the quotient Floor division Estimates average calories burned based on age, weight, heart rate, and time Calories burned equation Using math library for operations like power, absolute value, and square root Math functions Calculating frequencies of keys on a piano based on initial key frequency Frequency calculation Time taken for a substance to reduce to half its original value Half-life Outputting price change and estimated monthly mortgage based on current and last month's price House real estate summary Calculating product and average of floating-point numbers, rounding and formatting the output Simple statistics Determining the season based on input date and month, considering days in each month

Northern hemisphere seasons Spring: March 20 - June 20, Summer: June 21 - September 21, Autumn: September 22 - December 20, Winter: December 21 - March 19 Seasons A year with 366 days, occurring every 4 years and divisible by 4, except for century years not divisible by 400 Leap Year Primary highways: 1-99, odd for north/south, even for east/west. Auxiliary: 1 00-999, servicing the rightmost two digits of the primary highway Interstate Highway Numbers Score names: 'Eagle' (2 less than par), 'Birdie' (1 less), 'Par' (equals par), 'Bogey' (1 more); 'Error' if par not 3, 4, or 5 Golf Scores Used for multiple choices. 'if' for an option, 'elif' for alternatives, 'else' as the final option if none apply Conditional Statements Used to iterate a specific number of times or through elements in a list For Loop Used to iterate until a condition is met, breaking based on a condition rather than a specific number of iterations While Loop Loops within loops, used for complex iterations and operations Nested Loops Lists within lists, used for organizing and managing complex data structures