Docsity

TAMU ENGR 102 Python Coding Questions and Solutions, Exams of Java Programming

Toggle sidebar
bg1
TAMU ENGR 102 (python coding) questions with Complete
Solutions |Latest 2025 Update| 100%
Pass
x += c - ✔✔x = x + c
a -= 3 - ✔✔a = a - 3
x *= 4 - ✔✔x = x * 4
y /= 3 - ✔✔y = y / 3
what are some different types of variables? - ✔✔Integers, Floating-Point, Strings, Booleans
what is an integer? - ✔✔whole numbers, no decimals/fractions
what are floating-point numbers? - ✔✔numbers with a decimal point
what is boolean? - ✔✔single value either true or false
what are strings? - ✔✔way of describing text (you can use either single quotes or double
quotes)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download TAMU ENGR 102 Python Coding Questions and Solutions and more Exams Java Programming in PDF only on Docsity!

TAMU ENGR 102 (python coding) questions with Complete

Solutions |Latest 2025 Update| 100%

Pass

x += c - ✔✔x = x + c a - = 3 - ✔✔a = a - 3 x *= 4 - ✔✔x = x * 4 y /= 3 - ✔✔y = y / 3 what are some different types of variables? - ✔✔Integers, Floating-Point, Strings, Booleans what is an integer? - ✔✔whole numbers, no decimals/fractions what are floating-point numbers? - ✔✔numbers with a decimal point what is boolean? - ✔✔single value either true or false what are strings? - ✔✔way of describing text (you can use either single quotes or double quotes)

float(3) - ✔✔value becomes 3. int(4.9) - ✔✔has the value 4 str(10*1.0) - ✔✔has the value '10.0' what is the boolean value of true/false? - ✔✔true is assumed to have the value 1 false is assumed to have the value 0 x = 3 y = 4 print(str(x) + ':' + str(y)) - ✔✔3: how to ask the user for input? - ✔✔x = float(input()) == - ✔✔equal to != - ✔✔inequality a = 10 b = 10

while a == 0: print("About to change a") a = 1 print("Changing a back to 0") a = 0 - ✔✔About to change a Changing a back to 0 About to change a Changing a back to 0 ... (an infinite loop) what is the for loop designed to do? - ✔✔to perform specific statements for a determined number of iterations sum = 0 for i in range(10): sum += i+ print(sum) - ✔✔ 55 what are nesting loops? - ✔✔that is when you nest one loop inside another for i in range(3): print("i is", i)

for j in range(3): print(" j is", j) break - ✔✔i is 0 j is 0 i is 1 j is 0 i is 2 j is 0 what does the "break" statement do? - ✔✔it immediately stops that iteration in the loop! for i in range(10): if i%2 == 1: continue print("i is", i) - ✔✔i is 0 i is 2 i is 4 i is 6 i is 8 grades = [87, 93, 75, 100, 82, 91, 85]

[82, 91]

name = "Texas A&M University" print(name[6:9]) - ✔✔A&M how to create a dictionary? - ✔✔dictionary = { } :, separated by commas, in the {} dictionary = {'John' : 21, 'James' : 25} converting csv file to dataframe - ✔✔pd.read_csv(filepath) import mathplotlib submodule - ✔✔mathplotlib.pyplot as plt create numpy array - ✔✔np.array(list, type) how would you access a dictionary element? - ✔✔the value in the [] is the key. age['John'] = 21 what are the components of a hierarchy? - ✔✔tree, root, node (nodes without children are called leaves)

what is top-down design? - ✔✔a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve what is bottom-up design? - ✔✔in programming, you take simpler pieces of code and combining them to create more complex pieces of code when is it good to create a new function - ✔✔when you identify something that will be done repeatedly, create a function that will do it for you from turtle import * forward(100) left(90) forward(100) left(90) forward(100) left(90) forward(100) left(90) #To return to starting orientation input() #So that the window doesn't disappear - ✔✔(program draws a square) t.right(90) - ✔✔turtle turns right 90 degrees

how would you open a file named Results.out so that it can be written to, and assigning the designator to a variable called output_file - ✔✔output_file = open('Results.out', 'w') what is the alternative way to opening a file with an assignment and later closing? - ✔✔with as : (when you finish with the indented portion, then the file is automatically closed) format for writing files - ✔✔.write() different formats for reading files - ✔✔ = .readline() = .read() difference btwn = .readline() and = .read() - ✔✔.read() will read the entire file into one single string which could be problematic bc it can be a REALLY large string. .readline() will convert all the lines in the file into a list of strings and each element of the list is a string, giving one line of the program. what is the split method? - ✔✔it will convert a string into a list of strings, based on a separator that is specified. format for string splitting - ✔✔ = .split()

s = "1,2,3,4" elems= s.split(',') print(elems) - ✔✔['1', '2', '3', '4'] what are functions? - ✔✔basically a section of code that gets specified separately from the rest of the code. why are functions important? - ✔✔•prevents re-writing the same code repeatedly •helps to separate parts of code •is written separately from the rest of the code form of a function call - ✔✔() examples of built-in functions - ✔✔-print()

  • input()
  • float()
  • open()
  • len() what are tuples? - ✔✔like a list, but it can not change values!

defF(a): a += 1 return a a += 10 return a x = F(4) print(x) - ✔✔ 5 what are examples of a mutable data type? - ✔✔lists, dictionaries what are examples of immutable data type? - ✔✔boolean, integer, float, tuple, string types of errors - ✔✔syntax errors, run-time errors, logic errors syntax error - ✔✔an error that results when an instruction does not follow the syntax rules or grammar of the programming language. run-time errors - ✔✔error that occur when the program is being executed logic errors - ✔✔occurs when the program runs and executes, but the output is not what you wanted/expected

how to handle a run-time error - ✔✔try: except: types of built in exceptions - ✔✔TypeError, OSError, ZeroDivisionError