Python Exam Questions and Answers: Fundamentals Review, Exams of Nursing

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

2024/2025

Available from 07/15/2025

Lectjoshua
Lectjoshua 🇺🇸

4.5

(9)

24K documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Exam 1 Questions With Correct
Answers
What is the output of: 11.0//2 - CORRECT ANSWER✔✔-5.0
Floor division to the nearest whole number
Returns a float
What is the output of: 11//2 - CORRECT ANSWER✔✔-5
Return an int
What is the output of: 11/2 - CORRECT ANSWER✔✔-5.5
Returns a float
What is the output of: 11/2.0 - CORRECT ANSWER✔✔-5.0
What is the output of: 20%2 - CORRECT ANSWER✔✔-0
What is the output of: 21%2 - CORRECT ANSWER✔✔-1
What is the output of: 11%3 - CORRECT ANSWER✔✔-2
x = 'Texas A&M University'
x [-3] = ? - CORRECT ANSWER✔✔-i
x = 'Texas A&M University'
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Python Exam Questions and Answers: Fundamentals Review and more Exams Nursing in PDF only on Docsity!

Python Exam 1 Questions With Correct

Answers

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

[1, 2, 3] * 3 =? - CORRECT ANSWER✔✔-[ 1, 2, 3, 1, 2, 3, 1, 2, 3]

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.

  1. score = int(input('Enter your score: '))
  2. if score >= 90:
  3. -> letter = 'A'
  4. if score >= 80:
  5. -> letter = 'B'
  6. if score >= 70:
  7. -> letter = 'C'
  8. if score >= 60:
  9. -> letter = 'D'
  10. else:
  11. -> letter = 'F'
  12. print ('Letter grade:', letter) - CORRECT ANSWER✔✔-1, 2, 4, 6, 7, 12 C What is the exception order and output of this program below: Assume the user enters 65.
  13. score = int(input('Enter your score: '))
  14. if score >= 90:
  15. -> letter = 'A'
  16. if score >= 80:
  17. -> letter = 'B'
  18. if score >= 70:
  1. -> letter = 'C'
  2. if score >= 60:
  3. -> letter = 'D'
  4. else:
  5. -> letter = 'F'
  6. print ('Letter grade:', letter) - CORRECT ANSWER✔✔-1, 2, 4, 6, 8, 9, 12 D What is the exception order and output of this program below: Assume the user enters 50.
  7. score = int(input('Enter your score: '))
  8. if score >= 90:
  9. -> letter = 'A'
  10. if score >= 80:
  11. -> letter = 'B'
  12. if score >= 70:
  13. -> letter = 'C'
  14. if score >= 60:
  15. -> letter = 'D'
  16. else:
  17. -> letter = 'F'
  18. print ('Letter grade:', letter) - CORRECT ANSWER✔✔-1, 2, 4, 6, 8, 11, 12 F What is the exception order and output of this program below: Assume the user enters 99.
  1. -> letter = 'F'
  2. print ('Letter grade:', letter) - CORRECT ANSWER✔✔-If 90 in inputed then it will say that it is a B, because it satisfies the >80 condition and not the 90 condition, even though it is an A x = 1 y = 0 x >= 2 and y != 0 and (x/y) >2 =? - CORRECT ANSWER✔✔-False The (in) Operator is used to determine is a string contains an element of - CORRECT ANSWER✔✔-interest The (not in) operator determines whether a string _______ contain the element of interest. - CORRECT ANSWER✔✔-doesnt Sometimes you'd like your code to do different things depending on the current state - CORRECT ANSWER✔✔-if statements If you need to choose between 2 options use an - CORRECT ANSWER✔✔-if-else statement If you need more than two conditions then use the - CORRECT ANSWER✔✔-if elif else statement it is often necessary to do an operation repeatedly so one can use a - CORRECT ANSWER✔✔- while loop once the condition evaluates to false the ____ loop will stop executing - CORRECT ANSWER✔✔- while

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