a. Which of the options below implements a correct function thatreturns the absolute value of a given number?
1.
def abs(x):
return -1 * x
2.
def abs(x):
if (x < 0):
return -1 * x
3. def abs(x):
return 1 * -x
4. def abs(x):
if (x < 0):
return-1 * x
else: returnx
b. Which of the option below is equivalent to this piece ofcode:
piece of code .....
for i in range(9):
if (A > 5):
A= A + 5
1. i = 0
while (i <= 9):
if (A > 5):
A =A + 5
2. i = 0
while (i < 9):
if (A > 5):
A = A + 5
3. i = 1
while (i < 9):
if (A > 5):
4. i = 1
while (i <= 9):
if (A[i] > 5):
c.
Considering the command below, which one of the options wouldassign the value 7 to the variable "x"?
a = [ [1, 2, 3], [4, 5, 6], [7, 8, 9]]
Considering the command below, which one of the options wouldassign the value 7 to the variable "x"?
a = [ [1, 2, 3], [4, 5, 6], [7, 8, 9]]
x = a[2][0]
x = a[3][1]
x = a[7]
x = a[3,1]
A[i] = A[i] + 5
A[i] = A[i] + 5
d. What is the value of variable "s" after executing thecommands below? Use double quotes to delimit the variablecontent.
buf = "The quick brown fox"
s = buf[3:5]+buf[16:]
What is the value of variable "s" after executing the commandsbelow? Use double quotes to delimit the variable content.
buf = "The quick brown fox"
s = buf[3:5]+buf[16:]
"qfox"
"Thbr"
"Tqui"
"hox
e.
If I have a file named "grades.txt" and I want to open it toread its values in a variable called "ingrades". What would be thecommand to do so?
ingrades = open("grades.txt", "r")
ingrades = read("grades.txt", "r")
def(ingrades) = (r [grades.txt])
ingrades = open("r", grades.txt)
a. Which of the options below implements a correct function that returns the absolute value of a given number? 1. def ab
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am