Docsity

INTRODUCTION TO PYTHON PROGRAMMING AND DATA STRUCTURES EXAM SCRIPT UPDATED QUESTIONS AND A, Exams of Object Oriented Programming

Toggle sidebar
bg1
INTRODUCTION TO PYTHON
PROGRAMMING AND DATA STRUCTURES
EXAM SCRIPT UPDATED QUESTIONS AND
ACCURATE ANSWERS FULL SOLUTION
โ—โ— What data type is 3.14?
Answer: Float
โ—โ— What follows the in keyword in a for loop?
Answer: Iterable
โ—โ— Which loop is used when the number of iterations is known?
Answer: for
โ—โ— A while loop requires:
Answer: Condition + indented block
โ—โ— Which keyword exits a loop early?
Answer: break
โ—โ— In for item in list, item is:
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download INTRODUCTION TO PYTHON PROGRAMMING AND DATA STRUCTURES EXAM SCRIPT UPDATED QUESTIONS AND A and more Exams Object Oriented Programming in PDF only on Docsity!

INTRODUCTION TO PYTHON

PROGRAMMING AND DATA STRUCTURES

EXAM SCRIPT UPDATED QUESTIONS AND

ACCURATE ANSWERS FULL SOLUTION

โ—โ— What data type is 3.14? Answer: Float โ—โ— What follows the in keyword in a for loop? Answer: Iterable โ—โ— Which loop is used when the number of iterations is known? Answer: for โ—โ— A while loop requires: Answer: Condition + indented block โ—โ— Which keyword exits a loop early? Answer: break โ—โ— In for item in list, item is:

Answer: Value โ—โ— Which structure prevents duplicates? Answer: Set โ—โ— Which is immutable? Answer: Tuple โ—โ— To run Python code from a file: Answer: Save + interpreter โ—โ— Advantage of integrated terminal: Answer: No switching apps โ—โ— Navigate directory command: Answer: cd โ—โ— Interactive Python tool: Answer: Shell โ—โ— Slice last 3 characters: Answer: (-3:)

โ—โ— Default parameter syntax: Answer: name="World" โ—โ— Boolean return: Answer: return number > 0 โ—โ— Discount formula: Answer: price * (1 - percent/100) โ—โ— Password strong condition: Answer: letters + numbers + length โ—โ— Celsius to Fahrenheit: Answer: C * 9/5 + 32 โ—โ— Last character fix: Answer: text(-1) โ—โ— Even number check fix: Answer: return number%2== โ—โ— Larger number logic:

Answer: return larger โ—โ— range(5) produces: Answer: 0- 4 โ—โ— len("hello") = Answer: 5 โ—โ— Index starts at: Answer: 0 โ—โ— Boolean values are: Answer: True/False โ—โ— Function keyword: Answer: def โ—โ— Return keyword does: Answer: exits function with value โ—โ— List index access: Answer: list[0]

โ—โ— type(5) returns: Answer: int โ—โ— Convert string to int: Answer: int() โ—โ— Logical AND operator: Answer: and โ—โ— Logical OR operator: Answer: or โ—โ— What is the operator for logical OR? Answer: B โ—โ— What is the NOT operator? Answer: B โ—โ— What is the equality check operator? Answer: B โ—โ— What is the not equal operator?

Answer: B โ—โ— What does input() return by default? Answer: C. String โ—โ— How do you convert input to an integer? Answer: A. int(input()) โ—โ— Which is a valid variable name? Answer: C. name_ โ—โ— Which keyword defines a class? Answer: C. class โ—โ— Which symbol is used for exponentiation? Answer: B. ** โ—โ— What does // do? Answer: C. Floor division โ—โ— What is the modulus operator? Answer: B. %

โ—โ— What method removes whitespace from a string? Answer: B. strip() โ—โ— How do you split a string into a list? Answer: B. split() โ—โ— How do you join a list into a string? Answer: A. join() โ—โ— What must dictionary keys be? Answer: B. Unique โ—โ— How do you access a dictionary value? Answer: B. dict(key) โ—โ— How do you add a key-value pair to a dictionary? Answer: B. dict(key)=value โ—โ— How do you check if a key exists in a dictionary? Answer: A. key in dict โ—โ— What is None in Python?

Answer: C. Null value โ—โ— Which loop runs at least once? Answer: D. none โ—โ— What does a function without a return give? Answer: C. None โ—โ— What is the default function return type? Answer: C. None โ—โ— Which keyword is for optional loop skip? Answer: C. continue โ—โ— What does pass do? Answer: C. Does nothing โ—โ— How do you create an empty list? Answer: C. Both โ—โ— How do you create an empty dictionary? Answer: C. Both

โ—โ— What is not True? Answer: B. False โ—โ— Which is the correct comparison operator? Answer: B. == โ—โ— What is a function parameter? Answer: A. Input variable โ—โ— What is an argument? Answer: B. Passed value โ—โ— What is the scope of a local variable? Answer: B. Inside function โ—โ— What is the scope of a global variable? Answer: B. Entire program โ—โ— Which keyword modifies a global variable? Answer: A. global โ—โ— What does list slicing (1:3) mean?

Answer: B. index 1- 2 โ—โ— What does (::-1) do? Answer: B. Reverse โ—โ— What is the method to sort a list? Answer: A. sort() โ—โ— How do you copy a list? Answer: A. list.copy() โ—โ— What is the difference between = and copy()? Answer: B. Same object vs new object โ—โ— What is a list comprehension example? Answer: A. (x for x in list) โ—โ— What type of language is Python? Answer: B. Interpreted โ—โ—