Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Exam With 100% Correct And Verified Answers 2024, Exams of Advanced Education

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

2023/2024

Available from 08/03/2024

Qualityexam
Qualityexam 🇰🇪

2.5

(4)

2.7K documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Python Exam With 100% Correct And Verified Answers 2024 and more Exams Advanced Education in PDF only on Docsity!

Python Exam With 100% Correct And

Verified Answers 2024

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

  1. greet(name)
  2. name = input("enter your name: ")
  3. greet(name)
  4. def greet(person): u
  1. print("Hi,", person)
  2. greet(name) Which line or lines need to be removed from the above code so the program prints a greeting without error - Correct Answer-linens 1 and 3 vehicle_type = "Truck" if vehicle_type.upper().startswith("P"): print(vehicle_type, 'starts with "P"') else: print(vehicle_type, 'does not start with "P"') What is the output from running the above code? - Correct Answer-Truck does not start with "P" Hello World! What is the best choice of code to create the output shown above? - Correct Answer- print("Hello\nWorld!") A function with 2 integer parameters could start with which definition? - Correct Answer- def add_numbers(num_1, num_2): Which statement best describes a string in Python/Computer Science? - Correct Answer-sequence of characters Choose the statement that will print the letter "d", give the variable declaration word = "windows". - Correct Answer-print(word[3]) Which choice will print the word "tac", given the following variable declaration? word = "cat" - Correct Answer-print(word[::-1]) Which string method returns a index of first character or substring matches? - Correct Answer-.find() Which is valid Python code that will print "Green", give the following code? colors = ["Red", "Blue", "Green", "Yellow"] - Correct Answer-print(colors[2]) Which choice will return -1, given the following variable assignment below? word = "Python" - Correct Answer-word.find("Z") Which best describes the valid Python use of the following days List? - Correct Answer- days.append("Wednesday") days.append(14) print(days[-1]) ALL OF THE ABOVE

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?

  • Correct Answer-math.cell() Which function returns only whole, even numbers from within the range from 1 to 100? - Correct Answer-random.randrange(2, 101, 2)

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")