Partial preview of the text
Download WGU C859 Introduction to Programming in Python Guide | Syllabus & Study Tips and more Exams Programming Languages in PDF only on Docsity!
age 1 of 18 WGU C859 Introduction to Programming in Python OBJECTIVE ASSESSMENT ACTUAL EXAM STUDY GUIDE 2025/2026 ACCURATE QUESTIONS AND CORRECT DETAILED ANSWERS WITH RATIONALES | | 100% GUARANTEED PASS Floating-point Precision ......ANSWER........ format specification which indicates how many digits to the right of the decimal should be included in the output of floating types '{:.1 f}.format(1.725) produces 1.7 Replace (old and new parameters) ...... ANSWER........ returns a copy of the string with all occurrences of the substring old replaced by the string new; old and new arguments may be string variables or string literals age 2 of 18 ' me, 1 . phrase.replace(‘one’, ‘two’) will replace any occurrence of the word one with two Replace (old, new and count parameters) seees ANSWER........returns a copy of the string with all occurences of the substring old replaced by the new except only replaces the first count occurrences of old Slice Notation ......ANSWER........ my_str[start:end] will create a substring from my_str index start through to end — 1 Slice Notation with Stride sees ANSWER........my_str[start:end:stride] Field Width ...... ANSWER........ minimum number of characters that must be inserted into a string age 4 of 18 my_str.find('!’) will return the index of the '!’ in the string Find (with x, and start parameter) .....ANSWER........ string method that will return the index of the first occurrence of item x in the string but will begin looking at index start my_str.find('!’, 3) will produce the index of the first ! on or after index 3 Find (with x, start and end parameter) ....... ANSWER........ string method that will return the index of the first occurrence of item x in the string but will begin looking at the index start and will stop at index end -1 my_str.find('!', 3, 8) will produce the index of the first ! but will start looking at index 3 and stop looking at index 8 - 1 age 5 of 18 Rfind ...... ANSWER........ string method that works the same as str.find(x) but looks for the parameter in reverse, returning the last occurrence in the string my_str.rfind('!') will give the index of the last ! in the string Count .....ANSWER........string method that returns the number of times x occurs in the string my_str.count('oo') will return the number of times 'oo' occurs in the string isalnum() ......ANSWER.......¥ string method that returns true if all characters in the string are lowercase or uppercase letters or the numbers 0-9 isdigit() ......ANSWER........ string method that returns true if all characters are the numbers 0-9 age 7 of 18 lower() ...... ANSWER........ string method that returns a copy of the string with all characters lowercased upper() .....ANSWER........ string method that returns a copy of the string with all characters uppercased strip() ......ANSWER........ string method that returns a copy of the string with leading and trailing whitespace removed title() ...... ANSWER........ returns a copy of the string as a title, with the first letters of words capitalized split() ...... ANSWER........ string method that splits a string into a list of tokens each token is a substring that forms a part of a larger string parameter is a separator which indicates where to split the string into tokens (blank defaults to space) age 8 of 18 join() ...... ANSWER........ string method that joins a list of strings together with the parameter separating them my_str = '@'join(['billgates', 'microsoft']) = 'billgates@microsoft' mylist = [] ......ANSWER........ creates an empty list mylist = ['apple’, ‘banana’, ‘orange’ ......ANSWER......+« creates a list with the items apple, banana, and orange in it mylist[#] ...... ANSWER.......- will return the list item at the index of # mylist = list(‘abcd'’) ......ANSWER........ create a list of items a, b, c, and d mylist[start:end] ...... ANSWER.......« create a new list containing only those items at index start and end - 1 age 10 of 18 list.remove(x) ......ANSWER........ list method that Remove first item from list with value x list.pop() ......ANSWER........ list method that remove and return element at end of the list list.pop(i) .....ANSWER........ list method that removes and returns item at position i in list list.sort() ......ANSWER........ list method that sort the items of list in- place list.reverse() ...... ANSWER........ list method that reverse the elements of the list, in place list.index(x) ......ANSWER........ list method that return index of first item in list with value x age 11 of 18 list.count(x) ......ANSWER........ list method that return the number of times x appears in the list enumerate() ......ANSWER........ list function that iterates over a list and provides and iteration counter all(list) ...... ANSWER........ True if every element in list is True (!= 0), or if the list is empty any/(list) .....ANSWER........ True if any element in the list is True max(list) ......ANSWER........ Find the element in list with the largest value min(list) ......ANSWER........ Get the minimum element in the list sum(list) ......ANSWER........ Get the sum of all elements in the list age 13 of 18 List Comprehension new_list=[expression for item in list if condition] seeeee ANSWER........do the expression for each item in the list if a condition is true Conditional List Comprehension mylist.sort() .....ANSWER........ sort items of a list in ascending order; in-place modification mynewlist = sorted(mylist) .....ANSWER........ sorts items of a list in ascending order and creates a new list mynewlist = sorted(mylist, key=str.lower) .....ANSWER........ this will put all items in a list to lowercase before sorting them to ensure that a will come before B age 14 of 18 mynewlist = sorted(mylist, reverse=True) .....ANSWER........ create a new list sorted in reverse dict() ...... ANSWER........ implements a dictionary dict(Bobby='805-555-2232', Johnny='951-555-0055') dict([(‘Bobby', '805-555-2232'), (‘Johnny', '951-555-0055')]) my_dict[key] ...... ANSWER........ Indexing operation - retrieves the value associated with key jose_grade = my_dict['Jose’] my_dict[key] = value ..... ANSWER........ adds an entry if the entry does not exit, else modifies the existing entry my_dict['Jose'] = 'B+' age 16 of 18 Variable ..... ANSWER........ A piece of data that can vary Algorithm ....... ANSWER........ A sequence of instructions that solves a problem. Python Interpreter .....ANSWER........ A computer program that executes code written in the Python programming language. Interactive Interpreter .....ANSWER........ A program that allows the user to execute one line of code at a time Statement .....ANSWER........ A program instruction, typically Expressions .....ANSWER........ Code that returns a value when evaluated. age 17 of 18 Assignment ...... ANSWER......... A new variable is created by performing an assignment using the '=" symbol (eg. salary = wage * hours * weeks). Print() .....ANSWER........ Displays variables or expression values. Comments ......ANSWER........ Used to explain portions of code and are denoted by the '#' character in Python. String Literal ...... ANSWER........ Text enclosed in quotes. The text can have letters, numbers, spaces, or symbols. * Best practice will typically use single quotes around text. end = - weve ANSWER........ Keeps the next print's output on the same line separated by a single space. IPO ......ANSWER.....0 input, process, output