Python Programming, Liang Chapters 1-6 ., Exams of Advanced Education

Python Programming, Liang Chapters 1-6 .

Typology: Exams

2025/2026

Available from 04/24/2026

Allen_Nelson
Allen_Nelson 🇺🇸

5.6K documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ANSWER
Python Programming, Liang
Chapters 1-6 .
unicode (def, example) - ANSWERhexadecimal system for all international
characters, includes ASCII system for all English characters and symbols
i.e. print("\u6B22 \u8FCE \u03b1")
communication devices - ANSWERi.e. modems, network interface cards, DSL,
LAN
byte, bit, mega-, giga-, kilo- tera- - ANSWERbit = minimum unit of storage (i.e.
binary 1 or 0)
1 byte = 8 bits
kilobyte = 1000 bytes
megabyte = 1 million bytes
gigabyte = 1 billion bytes
terabyte - 1 trillion bytes
disks' storage space - ANSWERused for permanently storing data, 200-800
gigabytes can be stored
types of languages (3) - ANSWERmachine language - binary
assembly language - developed to make programming easier, uses words
high-level language- platform-independent language using statements (i.e.
Ada, Pascal, BASIC)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Python Programming, Liang Chapters 1-6 . and more Exams Advanced Education in PDF only on Docsity!

Python Programming, Liang

Chapters 1- 6.

unicode (def, example) - ANSWERhexadecimal system for all international characters, includes ASCII system for all English characters and symbols i.e. print("\u6B22 \u8FCE \u03b1") communication devices - ANSWERi.e. modems, network interface cards, DSL, LAN byte, bit, mega-, giga-, kilo- tera- - ANSWERbit = minimum unit of storage (i.e. binary 1 or 0) 1 byte = 8 bits kilobyte = 1000 bytes megabyte = 1 million bytes gigabyte = 1 billion bytes terabyte - 1 trillion bytes disks' storage space - ANSWERused for permanently storing data, 200- 800 gigabytes can be stored types of languages (3) - ANSWERmachine language - binary assembly language - developed to make programming easier, uses words high-level language- platform-independent language using statements (i.e. Ada, Pascal, BASIC)

OS techniques - ANSWERmultiprogramming: allows multiple programs to run simultaneously by sharing the same CPU multithreading: allows a single program to execute tasks at the same time multiprocessing / parallel processing: uses 2+ processors together to perform subtasks concurrently ''' ''' - ANSWERencloses a paragraph comment code to display addition, subtraction, multiplication and division of two numbers - ANSWERprint(x + y) print(x - y) print(x * y) print(x / y)

- ANSWERline comment, used for comments for documentation for

readers, ignored by Python runtime error - ANSWERoccurs when programmer gives Python something too hard to calculate (i.e. division by zero, int vs. string), program won't run logic error - ANSWERerror in math or other thing that causes the program to not function properly command to run another Python source file, "filename" - ANSWERpython filename.py

  • may contain letters, numbers and/or underscores
  • cannot start with a digit but may use digit
  • cannot be a keyword but may contain keyword cannot contain key symbols
  • CAN start with underscore tips for creating identifiers - ANSWERbe descriptive, use camelCase for more than one word, lowercase for variables, upper case for constants variables - ANSWERnames that reference values stored in memory (i.e. identifiers whose values are not constant) code for displaying area and radius after user inputted area and radius was calculated - ANSWERprint("The area is", area, "for radius", radius) easier way to code k = j = k i = j - ANSWERi = j = k = 1 scope of a variable - ANSWERpart of the program where the variable can be referenced simultaneous assignment of x = 1, y = 2, z = 3 - ANSWERx, y, z = 1, 2, 3 simple code for how to swap values x and y - ANSWERx, y = y, x

long code for how to swap values x and y (using temp) - ANSWERx = 1 y = temp = x x = y y = temp input statement for asking user to enter three numbers x y and z - ANSWERx, y, z = eval(input("Enter three numbers separated by commas.")) #input must be separated by commas types of division (2) - ANSWER/ float division: to get a decimal (even if operands are integers and even if there are other math operators!!) // integer division: to get an integer (no rounding; all .decimals are stripped off) types of numeric data (2) - ANSWERinteger: 1, 73, - 12 float: 1.0, 23.5, - 12. unary versus binary operators, examples - ANSWERunary: only one number it it operates on (-5) binary: two numbers it operates on (5-4) code for determining whether x is even or odd number - ANSWERx%2 =0 if even, x%2 = 1 if odd

int(x) 5 2)Used to convert str to int int(input(x)) round - ANSWERrounds a number to the nearest whole value, if it is equally close to 2 integers, the even one is returned x = 4. round(x) 4 eval vs. int - ANSWERsame for integer with quotes, must be eval for float in quotes and math in quotes, must be int if it starts with 0's in quotes int("34") = eval("34") int("3.4") does not work, eval("3.4") does int ("3 + 4") does not work, eval ("3 + 4") does BUT int("003") does work and eval("003") doesn't. code for how to convert to two decimal places for $ amounts - ANSWERint(x

    1. / 100.0) UNIX epoch - ANSWERimport time time.time()

current time in seconds since 00:00:00 on 1/1/1970 (when UNIX Os was introduced) software development process (7) - ANSWERRequirements specification (to run the program, the system needs xyz capability) System analysis (identify input and output) System design (IPO steps of program, #) Implementation (coding, self-testing, debugging) Testing (independent team) Deployment Maintenance formula for monthly payment of loan - ANSWERmonthlyPayment = loanAmount * monthlyInterestRate / (1-1 / (1 + monthlyInterestRate) ** (numberOfYears * 12)) totalPayment = monthlyPayment * numberOfYears * 12 code for square root of a - ANSWERa ** 0. code for calculating distance between two points - ANSWERdistance = ((x1 - x2) * x1-x2)) + ((y1 - y2) * (y1-y2)) ** 0. code to find absolute value of z - ANSWERabs(x)

how to get absolute value for integer x as a float - ANSWERmath.fabs(x) how to round x up to its nearest integer - ANSWERmath.ceil(x) how to round x down to it nearest integer - ANSWERmath.floor(x) how to get the natural logarithm of x - ANSWERmath.log(x) how to get the square root of x - ANSWERmath.sqr(x) how to get logarithm of x for specified base - ANSWERmath.log(x, base) how to get the sin, cosine and tangent of (x,x) - ANSWERmath.sin(x) math.cos(x) math.tan(x) how to convert angle x from radians to degrees, from degrees to radians - ANSWERmath.degrees(x) math.radians(x) ' ' versus '' '' - ANSWERboth used to convey a string conventionally '' '' used for >1 character ' ' used for single character or empty string because it is easier to convert to other languages

function for returning ASCII code for character a - ANSWERch = 'a' ord(ch) or ord('a') function for returning character represented by ASCII code 'x' - ANSWERchr(x) how to find uppercase representation of any lowercase letter - ANSWERoffset = ord('a') - ord('A') lowercaseletter = 'h' uppercaseletter = chr(ord(lowercaseletter) - offset) uppercaseLetter (difference is always 32) escape sequence (8) - ANSWER\n new line, line break or EOL \f forces printer to print from next page \r moves cursor to first position on same line \b backspace \t tab \ backslash \' single quote

remainingamount = int(x * 100) numberofDollars = remainingamount // 100 remainingamount = remainingamount % 100 numberofQuarters = remainingamount // 25 remainingamount = remainingamount % 25 numberofdimes = remainingamount // 10 remainingamount = remainingamount % 10 numberofnickels = remainingamount // 5 remainingamount = remainingamount % 5 numberofpennies = remainingamount how to get id, type / class of object x - ANSWERid(x) type(x) change case for string x - ANSWERx = "string" y = x.lower() or y = x.upper() y

how to remove white space for string "\t string \n" - ANSWERx = "\t string \n" y = x.strip() y format the number 1.2345 to show only two decimals and have three blank spaces in front of it - ANSWERprint(format(1.2345, "3.2f") output for print(format(1.23456, ".3f") output for print(format(1.2, "10.3f") - ANSWER1.

output for print(format(57. - ANSWER convert 0.53467 to display as percent - ANSWERprint(format(0.53467, ".2%")) show 0.9812 as a percent with one space in front of it - ANSWERprint(format(0.9812, "7.2%")) show 45.678 left justified with one decimal place - ANSWERprint(format(45.678, "<.2f")) #this will also round it show hexadecimal value of 12345 with 10 spaces in front - ANSWERprint(format(12345, "10x"))

output for 1 + 1 == 2 - ANSWERTrue how to check whether a number n is even - ANSWERn % 2 == 0 how to check whether a number is a multiple of x - ANSWERn % x == 0 go to next line - ANSWER elif is the same as (structure) - ANSWERelse: if: condition \ - ANSWERgo to next line or ignore next item logical operators - ANSWERand, or, not not x and y is the same as - ANSWERnot x or y not (x or y) is the same as - ANSWERnot x and not y leap year - ANSWERleap year % 4 == 0 another way to say if x > 0: y = 1

else: y = - 1 - ANSWERy = 1 if x > 0 else - 1 division - ANSWER/ how to determine whether given point z is inside a circle - ANSWERif distance from z to center of circle is > radius of circle output for print("item", end = '') print ("seconditem") - ANSWERitem seconditem speed of CPU measured in ... - ANSWERmegahertz (1 million pulses per second) NIC device - ANSWERused to connect computer to local area network (LAN) to start python from command prompt, use command - ANSWERpython to run python file script named t.py, use the command - ANSWERpython t.py eval(1 + 2) - ANSWERerror eval("1 + 2") - ANSWER 3

syntax for simple for loop - ANSWERfor value in sequence: Statements basic parts of while loop - ANSWERwhile continuation condition: Statements Additional statements for controlling the loop sentinel value - ANSWERadditional x = 0, x = x + 1 type value that signifies the end of the loop, common technique for controlling the loop, should never be floating point values syntax of while loop with sentinel value - ANSWERx = eval(input("Enter x.")) sum = 0 while x != 0: sum += x x = eval(input("Enter x.")) print ("The sum is," sum) input redirection - ANSWERstoring data in text file and running it from python how to run program for text file on Python file python.py - ANSWERpython python.py < input.txt

output redirection - ANSWERsend output to file instead of displaying it on Python screen how to send py file text.py to outside text - ANSWERpython text.py > output.txt output for for v in range (4,8) print(v) - ANSWER 4 5 6 7 8 output for for v in range(3, 9, 2) print(v) - ANSWER 3 5 7 output for for i in range(1,5): j = 0 while j < 1: print(j, end = "")