Tuesday, September 17, 2019

Why we use escape sequences and which escape sequences are available in Python. Compile a list (At least 10) of each of these with a short description of their functions.


               

           Well, before we get to why, we must know what an escape sequence is in Python. In python the backslash is “\” is what is known as the escape and the sequence represents certain whitespace character. In detail we use it because Escape sequence is two or more than two character which mostly begin with escape character (\). This escape character gives special instruction to the interpreter in python to perform some function or command to be precise.
Here is list of examples gotten from the source below. It helps us understand how each sequence works and benefits every user.


Escape Sequence
Description
Example
Output
\\
Prints Backslash
print "\\"
\
\`
Prints single-quote
print "\'"
'
\"
Pirnts double quote
print "\""
"
\a
ASCII bell makes ringing the bell alert sounds ( eg. xterm )
print "\a"
N/A
\b
ASCII backspace ( BS ) removes previous character
print "ab" + "\b" + "c"
ac
\f
ASCII formfeed ( FF )
print "hello\fworld"
hello
         world
\n
ASCII linefeed ( LF )
print "hello\nworld"
hello
world
\N{name}
Prints a character from the Unicode database
print u"\N{DAGGER}"
\r
ASCII carriage return (CR). Moves all characters after ( CR ) the the beginning of the line while overriding same number of characters moved.
print "123456\rXX_XX"
XX_XX6
\t
ASCII horizontal tab (TAB). Prints TAB
print "\t* hello"
    * hello
\t
ASCII vertical tab (VT).
N/A
N/A
\uxxxx
Prints 16-bit hex value Unicode character
print u"\u041b"
Л
\Uxxxxxxxx
Prints 32-bit hex value Unicode character
print u"\U000001a9"
Æ©
\ooo
Prints character based on its octal value
print "\043"
#
\xhh
Prints character based on its hex value
print "\x23"
#
LinuxConfig.org



Python: Area of a rectangle

Python: Area of a rectangle
Write a Python code that calculates the area of a rectangle.
In Euclidean plane geometry, Area of a rectangle is:
      Area = length * width
Check the posted image that represents the area of a rectangle.
Use print () function and write the python code
Insert Width 5 and length 4
Run the code, take a snap shot OR Snip it, paste on MS Word and drop it in the drop box.


Quiz 2 Chapter 2: Software Development, Data Types, and Expressions

  • Question 1

    4 out of 4 points
    What statement accurately reflects the difference between the quotient operator and the division operator?
    Correct Answer:
    Correctd. 
  • Question 2

    4 out of 4 points
    In the waterfall development model, what is the most expensive part of software development?
    Correct Answer:
    Correctb. 
  • Question 3

    4 out of 4 points
    What function can you call inside of IDLE to show the resources of the math module, once it has been imported?
    Correct Answer:
    Correctc. 
  • Question 4

    4 out of 4 points
    Which of the following functions and expressions will convert the ASCII character "Z" to its numeric equivalent ASCII code?
    Correct Answer:
    Correcta. 
  • Question 5

    4 out of 4 points
    In general, a variable name must begin with either a letter or an underscore (_).
    Correct Answer:
    Correct True
  • Question 6

    4 out of 4 points
    A variable associates a name with a value, making it easy to remember and use the value later in a program.
    Correct Answer:
    Correct True
  • Question 7

    4 out of 4 points
    Modern software development is usually incremental and iterative.
    Correct Answer:
    Correct True
  • Question 8

    4 out of 4 points
    What print statement will output a single '\' character?
    Correct Answer:
    Correctc. 
  • Question 9

    4 out of 4 points
    Expressions provide an easy way to perform operations on data values to produce other data values.
    Correct Answer:
    Correct True
  • Question 10

    4 out of 4 points
    1,500 is a valid integer literal in Python.
    Correct Answer:
    Correct False
  • Question 11

    4 out of 4 points
    Real numbers have infinite precision, which means that the digits in the fractional part can continue forever.
    Correct Answer:
    Correct True
  • Question 12

    4 out of 4 points
    You can use parentheses to change the order of evaluation in an arithmetic expression.
    Correct Answer:
    Correct True
  • Question 13

    4 out of 4 points
    string is an example of a data type in Python.
    Correct Answer:
    Correct False
  • Question 14

    0 out of 4 points
    How does the int function convert a float to an int?
    Correct Answer:
    Correctb. 
  • Question 15

    4 out of 4 points
    Variables receive their initial values and can be reset to new values with an assignment statement.
    Correct Answer:
    Correct True
  • Question 16

    4 out of 4 points
    In Python, \b is a escape sequence that represents a horizontal tab.
    Correct Answer:
    Correct False
  • Question 17

    4 out of 4 points
    The cost of developing software is spread equally over the phases.
    Correct Answer:
    Correct False
  • Question 18

    4 out of 4 points
    In Python, what data type is used to represent real numbers between -10^308 and 10^308 with 16 digits of precision?
    Correct Answer:
    Correcta. 
  • Question 19

    4 out of 4 points
    In evaluating the precedence rules used by Python, what statement is accurate?
    Correct Answer:
    Correctc. 
  • Question 20

    0 out of 4 points
    What statement accurately describes the analysis phase of the waterfall model?
    Correct Answer:
    Correctc. 
  • Question 21

    4 out of 4 points
    You are reviewing the code written by another programmer, and encounter a variable whose name is entirely in capital letters. What might you discern from this variable name?
    Correct Answer:
    Correctc. 
  • Question 22

    4 out of 4 points
    Functions that are always available in Python come from what module?
    Correct Answer:
    Correctb. 
  • Question 23

    4 out of 4 points
    What effect does the following print statement have? print("Hello" * 5)
    Correct Answer:
    Correcta. 
  • Question 24

    4 out of 4 points
    What is the largest value of an int data type in the Python programming language?
    Correct Answer:
    Correctb. 
  • Question 25

    4 out of 4 points
    Text processing is by far the least common application of computing.
    Correct Answer:
    Correct False