Mathematical functions, strings and objects Flashcards

(27 cards)

1
Q

What is ASCII?

A

ASCII (American Standard Code for Information Interchange) is an 8-bit encoding scheme for representing all uppercase and lowercase letters, digits, punctuation marks, and control characters. ASCII uses numbers 0 through 127 to represent characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ASCII (American Standard Code for Information Interchange), an 8-bit _____ ______ for representing all _____ and ______ letters, _____, _______ ______, and ______ ______. ASCII uses numbers ____ through _____ to represent characters.

A

ASCII (American Standard Code for Information Interchange), an 8-bit encoding scheme for representing all uppercase and lowercase letters, digits, punctuation marks, and control characters. ASCII uses numbers 0 through 127 to represent characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Unicode is…

A

…an encoding scheme for representing international characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What will be displayed by print(ord('z') - ord('a'))?
 A. 25
 B. 26
 C. a
 D. z
A

A. 25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Suppose x is a char variable with a value 'b'. What will be displayed by the statement print(chr(ord(x) + 1))?
 A. a
 B. b
 C. c
 D. d
A

C. c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An escape sequence is a special notation that consists of a ________ followed by a _______ or a combination of ______.

A

An escape sequence is a special notation that consists of a backslash () followed by a character or a combination of digits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The backslash \ is called an ______ _______

A

escape character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you display the characters \ and “?

A

print(“\”)

print(“"”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Which of the following statement prints smith\exam1\test.txt?
 A. print("smith\exam1\test.txt")
 B. print("smith\\exam1\\test.txt")
 C. print("smith\"exam1\"test.txt")
 D. print("smith"\exam1"\test.txt")
A

B. print(“smith\exam1\test.txt”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What will be displayed by the following code?

print(“A”, end = ‘ ‘)
print(“B”, end = ‘ ‘)
print(“C”, end = ‘ ‘)
print(“D”, end = ‘ ‘)

A. ABCD
B. A, B, C, D
C. A B C D
D. A, B, C, D will be displayed on four lines

A

C. A B C D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?
 A. print(i)
 B. print(str(i))
 C. print(int(i))
 D. print(chr(i))
A

D. print(chr(i))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
The expression "Good " + 1 + 2 + 3 evaluates to \_\_\_\_\_\_\_\_.
 A. Good123
 B. Good6
 C. Good 123
 D. Illegal expression
A

D. Illegal expression

Hint: In Python, the + operator cannot be used to concatenate a string with a number. The number needs to be converted to a string using the str(number) function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Suppose you entered A and Z when running the following code. What is the output?
x = input(“Enter a character: “)
y = input(“Enter a character: “)
print(ord(y) - ord(x))

A

25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
What is max("Programming is fun")?
 A. P
 B. r
 C. a blank space character
 D. u
 E. n
A

D. u

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
What is min("Programming is fun")?
 A. P
 B. r
 C. a blank space character
 D. u
 E. n
A

C. a blank space character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
What is "Programming is fun"[-1]?
 A. Pr
 B. P
 C. fun
 D. n
 E. un
17
Q

Suppose that s1 and s2 are two strings, given as follows:
s1 = “Welcome to Python”
s2 = “to”
What are the results of the following expressions?
a. s1[4]
b. s1[-4]

A

a. s1[4] is o

b. s1[-4] is t

18
Q
What is "Programming is fun"[4: 6]?
 A. ram
 B. ra
 C. r
 D. pr
 E. pro
19
Q
What is "Programming is fun"[-3:-1]?
 A. Pr
 B. P
 C. fun
 D. un
 E. fu
20
Q
What is "Programming is fun"[:2]?
 A. Pr
 B. P
 C. Pro
 D. Programming
 E. Programming is
21
Q

In Python, all data—including numbers and strings—are actually ________.

22
Q
Given a string s = "Programming is fun", what is s.find('rom')?
 A. 1
 B. 2
 C. 3
 D. 4
 E. -1
A

E. -1

No matching is found. It returns -1.

23
Q

The characters ‘ ‘, \t, \f, \r, and \n are called the __________ characters

A

The characters ‘ ‘, \t, \f, \r, and \n are called the whitespace characters

24
Q
Suppose s is "\t\tWelcome\n", what is s.strip()?
 A. \t\tWelcome\n
 B. Welcome\n
 C. \t\tWELCOME\n
 D. Welcome
A

D. Welcome

Hint: The s.strip() method returns a new string with the whitespace characters removed.

25
The format function returns _______. A. an int B. a float C. a str
C. a str
26
``` Suppose x is 345.3546, what is format(x, "10.3f")? (note b represents a blank space) A. bb345.355 B. bbb345.355 C. bbbb345.355 D. bbb345.354 E. bbbb345.354 ```
B. bbb345.355 Hint: 10.3f specifies 3 digits after the decimal point and round up the remaining digits. The total width is 10.
27
Suppse number contains integer value 4, which of the following statement is correct? A. print(format(number, "2d"), format(number ** 1.5, "4d")) B. print(format(number, "2d"), format(number ** 1.5, "4.2d")) C. print(format(number, "2d"), format(number ** 1.5, "4.2f")) D. print(format(number, "2f"), format(number ** 1.5, "4.2f")) E. print(format(number, "2.1f"), format(number ** 1.5, "4.2f"))
C. print(format(number, "2d"), format(number ** 1.5, "4.2f")) D. print(format(number, "2f"), format(number ** 1.5, "4.2f")) E. print(format(number, "2.1f"), format(number ** 1.5, "4.2f")) Hint: number ** 1.5 is a floating-point value and must be formatted using the specifier f, not d.