

















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
Python exam questions with answers, covering data types, operators, string manipulation, control flow (if statements, loops), and basic functions. Questions include integer/float division, string indexing/slicing, boolean operators, and list manipulation. Designed to test python syntax and basic programming logic, it's useful for students learning python. Questions are clear and concise, with answers following each question for quick review. Useful for python exams/quizzes and reinforcing python fundamentals. It covers arithmetic operations, list manipulation, and control flow, providing a comprehensive review. Execution order questions help students understand code execution, crucial for debugging.
Typology: Exams
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















What is the output of: 11.0//2 - CORRECT ANSWER✔✔-5. Floor division to the nearest whole number Returns a float What is the output of: 11//2 - CORRECT ANSWER✔✔- Return an int What is the output of: 11/2 - CORRECT ANSWER✔✔-5. Returns a float What is the output of: 11/2.0 - CORRECT ANSWER✔✔-5. What is the output of: 20%2 - CORRECT ANSWER✔✔- What is the output of: 21%2 - CORRECT ANSWER✔✔- What is the output of: 11%3 - CORRECT ANSWER✔✔- x = 'Texas A&M University' x [-3] =? - CORRECT ANSWER✔✔-i x = 'Texas A&M University'
x [3] =? - CORRECT ANSWER✔✔-a x = 'Texas A&M University' len(x) =? - CORRECT ANSWER✔✔- x = 'Texas A&M University' x [0:5:2] =? - CORRECT ANSWER✔✔-Txs It starts at 0 and ends at 5, incremented by 2 x = 'Texas A&M University' x [4:] =? - CORRECT ANSWER✔✔-s A&M University x = 'Texas A&M University' x [:4] =? - CORRECT ANSWER✔✔-Texa x = 'Texas A&M University' 'A' in x =? - CORRECT ANSWER✔✔-True Acts as a Boolean, determines if it is in the string x = 'Texas A&M University' 't' in x =? - CORRECT ANSWER✔✔-True x = 'Texas A&M University' 'A&M' in x =? - CORRECT ANSWER✔✔-True
x = 1 y = 0 x >= 2 and (x/y) >2 =? - CORRECT ANSWER✔✔-False x = 6 y = 2 x >= 2 and (x/y) >2 =? - CORRECT ANSWER✔✔-True x = 1 y = 0 x >= 2 and y != 0 and (x/y) >2 =? - CORRECT ANSWER✔✔-False What is the purpose of the "def" keyword in Python? - CORRECT ANSWER✔✔-It indicates that start of a function It indicates that the follow indented section of code id to be stored for later What will the following Python program print out? def fred(): -> print ("Zap") def jane(): -> print ("ABC")
jane() fred() jane() - CORRECT ANSWER✔✔-ABC Zap ABC What will the following Python program print out? count = 0 for number in [3, 41, 12, 9, 74, 15]: -> count = count + 1 print('Count: ', count) - CORRECT ANSWER✔✔-Count: 6 What will the following Python program print out? total = 0 for number in [3, 41, 12, 9, 74, 15]: -> total = total + number print('Total: ', total) - CORRECT ANSWER✔✔- It will add all of the numbers together What will the following Python program print out? cheeses = ['Cheddar', 'Edam', 'Gouda'] 'Edam' in cheeses - CORRECT ANSWER✔✔-True
print (t) =? - CORRECT ANSWER✔✔-['s', 'p', 'a', 'm'] What is the exception order and output of this program below: Assume the user enters 75.
Provides a clean iteration syntax. note the colon and indentation >> for i in range(0, 3): >> print(i*2) 0 2 4 >> m_list = ["Sir", "Lancelot", "Coconuts"] >> for item in m_list: >> print(item) Sir Lancelot Coconuts >> w_string = "Swift" >> for letter in w_string: >> print(letter) S w i f t - CORRECT ANSWER✔✔-For loop This function will return a random integer between a and b including a and b - CORRECT ANSWER✔✔-random.randint(a,b)
if you cannot predetermine how often a loop repeats then you ust use a - CORRECT ANSWER✔✔-while lop / - CORRECT ANSWER✔✔-dividing with remainders // - CORRECT ANSWER✔✔-dividing without remainders ** - CORRECT ANSWER✔✔-exponentiation != - CORRECT ANSWER✔✔-not equal int - CORRECT ANSWER✔✔-signed integers bool - CORRECT ANSWER✔✔-true, false float - CORRECT ANSWER✔✔-numbers with decimals The position (or index) of each of the characters in the string are given below from left to right - CORRECT ANSWER✔✔-start at 0 The position (or index) of each of the characters in the string are given below from right to left - CORRECT ANSWER✔✔-start at - Slice Notation for strings: - CORRECT ANSWER✔✔-finding subsets of strings
gives the character from the string x in location a - CORRECT ANSWER✔✔-x[a] gives the characters from the string x starting at index a and ending at index b-1 - CORRECT ANSWER✔✔-x[a:b] gives the characters from teh string x starting at index a and ending at index b-1 where each index is incremented by c. - CORRECT ANSWER✔✔-x [a:b:c] if the position of a is missing the default value is - CORRECT ANSWER✔✔- if position b is missing the default value is the length of string; - CORRECT ANSWER✔✔-and if position c is missing, the default value is - CORRECT ANSWER✔✔- == - CORRECT ANSWER✔✔-equal sign is the repetition operation - CORRECT ANSWER✔✔-* What is the output? x = 'peach' print x[1:4] - CORRECT ANSWER✔✔-eac What is the type of variable a? a = 5 / 10 - CORRECT ANSWER✔✔-float
x = 0 while x < 8: -> x = x + 3 print(x) What is the output of the program? - CORRECT ANSWER✔✔- Find the errors for the program, write the corrected version of this program. 1 choice = 35 2 if choice > 40: 3 print 'A' 4 elif choice > 30: 5 print 'B' 6 else: 7 print 'C' 8 print 'D' - CORRECT ANSWER✔✔-1 choice = 35 2 if choice > 40: 3 -> print 'A' 4 elif choice > 30: 5 -> print 'B' 6 else: 7 -> print 'C' 8 print 'D' OR
6 else: 7 -> print 'C' 8 -> print 'D' T/F a) Variables are case-sensitive. - CORRECT ANSWER✔✔-True T/F b) In Python, single and double quotation marks are valid. But, triple quotation marks are invalid. - CORRECT ANSWER✔✔-False T/F c) Strings are immutable in Python. - CORRECT ANSWER✔✔-True T/F d) In while loop, The statements in will be executed as long as the condition evaluates to False. - CORRECT ANSWER✔✔-False T/F e) It is impossible to write an infinite loop in Python. - CORRECT ANSWER✔✔-False Write the o/p for the program: a = (1, 3, 4, 'Aggies') print(len(a)) - CORRECT ANSWER✔✔-lengh of a: 4 Write the o/p for the program: a = (1, 3, 4, 'Aggies') print(a[::-1]) - CORRECT ANSWER✔✔-reversed: ('Aggies', 4, 3, 1)
daysinmonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] leap_year = True if leap_year: daysinmonth[1] = 29 print("There are",daysinmonth[0],"days in the month of January") - CORRECT ANSWER✔✔- There are 31 days in the month of January Write the o/p for the program: (8 points) daysinmonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] leap_year = True if leap_year: daysinmonth[1] = 29 print(daysinmonth[1],"days in February") - CORRECT ANSWER✔✔-29 days in February { } - CORRECT ANSWER✔✔-set ____ variables hold constant values. That is once the value of a _____ variable is set, the value of the ____ variable never changes in your program - CORRECT ANSWER✔✔-Global _____ variablees may not hold non-constant values. That is if the keyword global appears in your program your program will be considered incorrect - CORRECT ANSWER✔✔-global ____ are immutable - CORRECT ANSWER✔✔-Tuples
Both ___ and ____ share the immutability criterion - CORRECT ANSWER✔✔-Strings, Tuples An___ object is a list of tuples (immutable lists, each containing an index and value pair - CORRECT ANSWER✔✔-enumerate A useful string method is join which joins a list of strings back together using a string as separator. You can only join a list of strings. You cannot join a list of integers floats or Booleans - CORRECT ANSWER✔✔-sep.Join A ___ is used to contain an unordered collection of objects. These elements are never duplicated - CORRECT ANSWER✔✔-set _____ are unordered and cannot be indexed by numbers - CORRECT ANSWER✔✔-set ____ support a standard collection of operations including union , interaction, difference and symmetric difference - CORRECT ANSWER✔✔-sets New items can be added to a set using - CORRECT ANSWER✔✔-add( ) or update( ) the function of a list looks like - CORRECT ANSWER✔✔-[ ] A function that sees what two sets have in common - CORRECT ANSWER✔✔-intersection A function that puts two sets together - CORRECT ANSWER✔✔-union The _____ function places a single element in the set. - CORRECT ANSWER✔✔-add( )