Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive set of python exam questions and their correct answers for the year 2024. It covers a wide range of topics, including string manipulation, file handling, data structures, mathematical operations, and more. The questions are designed to test the student's understanding of python programming concepts and their ability to apply them in practical scenarios. An excellent resource for students preparing for python exams, as it offers a structured and verified set of questions and answers that can be used for study, practice, and exam preparation. The detailed explanations and step-by-step solutions provided for each question make this document a valuable tool for both beginners and experienced python programmers.
Typology: Exams
1 / 4
Given the following string: S = "Welcome: which code results in an error? - Correct Answer-Print(S+1) What is the output of the following code? name = 123 if name.startswith("a") print("welcome") - Correct Answer-An error message Which statements evaluate True and without errors? (Choose all that apply.) - Correct Answer-"The Title".istitle() "upper".islower() What is the order of precedence (from first to last) of the math operators? - Correct Answer-*, /, +, - What is the output of the following code? print("She said, \ "Who's there?") - Correct Answer-She said, "Who's there?" Which operator can be used to combine two strings? - Correct Answer-+ Which is not a way to run a code cell in Jupyter Notebook? - Correct Answer-Shift + R Which is an example of Python string addition that will run without error? - Correct Answer-Falsenew_string = "Hello": + "World!" PriNt("Hello World") will not output the message "Hello World!". What will it result in? - Correct Answer-NameError Which is a properly formatted Python print() function example? - Correct Answer- print("Welcome the", 3, "New students!") Which code formats the string "Green" to "GREEN" - Correct Answer-.upper() name = "SKYE HOMSI" print("y" in name.lower()) What is the output from the above code? - Correct Answer-True
Which code overwrites (replaces) the "0" with a "5" in the following numbers list? numbers = [1, 1, 0] - Correct Answer-numbers[2] = 5 Choose the item that best completes the following sentence: "After using an insert on a Python list..." - Correct Answer-the length of the list increases by 1 Which code is the best use of Python that deletes the "5" i the following numbers list? numbers = [7, 1, 5, 8, 0] - Correct Answer-del numbers[2] Which code will result in the ltr_cnt = 2 for counting the letter "c" found in the following test_string? test_string = 'Mexico City' - Correct Answer-- Which Python code results in output of a sorted scores list with changing the original scores list below to be in a sort order? scores = [0, 5, 2, 11, 1, 9, 7] - Correct Answer-print(scores.sort()) Which code is the best use of Python to iterate through the list "numbers"? numbers = [7, 1, 5, 8, 0] - Correct Answer-for range[5] in numbers: for int in list: for number in numbers: NONE OF THE ABOVE Which is the best choice to complete the following sentence? Opening a file in Python using read mode ('r')... - Correct Answer-makes file contents available for Python to read fro the file Which answer best describes what .strip() does in the following code sample? poem_line = poe1.readline().strip() - Correct Answer-.strip() removes all whitespace in a string, including the '\n' formatting character To move the pointer in an open file to the first character, what should you use? - Correct Answer-.seek(0) Which code should you use to import a function named abc from a Python module named xyz? - Correct Answer-from xyz import abc When using Python, which athematic operation returns a value of 2> - Correct Answer- 42 % 4 Which function from the math module can you use to round up the number 12.34 to 13?
Which attributes can you define for a time object? (Choose all that apply.) - Correct Answer-Hour Second Which function can you use to list the contents of the current working directory? - Correct Answer-os.listdir() Which type of statement should you use as a placeholder for future function code? - Correct Answer-pass Which Boolean operator has the highest precedence? (Choose one.) - Correct Answer- is not When using printf-style string formatting, which conversion flag outputs a signed integer decimal? - Correct Answer-%d When using the str.format() method, which flag places a - (negative sign) in front of negative numbers? - Correct Answer-" Which string defines heterogeneous tuple? - Correct Answer-T = ("Tobias", 23, 25.3, []) Which process does Python use to optimize dictionary search capabilities? - Correct Answer-hashing Which two statements about key:value pairs are correct? (Choose two) - Correct Answer-Keys are unique A value can be associated with multiple keys What type of loop should you use to iterate over the elements of a simple table (two- dimensional list)? - Correct Answer-Nested When using Python, what is the result of the mathematic operation 1 ** (2*3) / 4 +5? - Correct Answer-5. Which function displays a date object in the form Monday, January 01, 2018 - Correct Answer-.strftime("%A, %B %d %Y")