EECS138 midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

what is the type of function of the answer to "Are you left handed?"; left_handed=false

#bool

what is the type of function of the cost of a move to download; price=3.99?

#float

what is the type of function of the number of people in your family; fam=4?

#int

what is the type of function of your initials; inits = "ACJ"?

#str

math.ceil(-1.38)

-1

math.floor(-1.38)

-2

In Python, what is the value returned by the following built-in function call?: int(-2.9) False, since -2.9 is a float not an integer -2, truncates toward zero -3, rounds to the nearest integer an error, since -2.9 is a float not an integer

-2, truncates toward zero

8 // 13

0

13 // 8

1

math.floor(1.38)

1

math.log(math.e)

1

46 % 9 + 4 * 4 - 2**3

1 + 16 - 8 = 9

write a boolean expression that evaluates if a number is between 1 and 100, inclusive

1 <= n and n <= 100

what will be the output for the following code? x = 1 while x < 7: print(x) x += 2

1, 3, 5

round (13/8, 1)

1.6

13 / 8

1.625

for j in range(100, 0, -10): print("*")

100,90,80,70,60,50,40,30,20,10: ANSWER: 10

How many items are there in range(-3, 10) ? 10 13 14 0, because it gives an error on negative numbers

13

determine how many asterisks are printed in each loop below: for i in range(138): print("*")

138

Which of the following statements would give an error in Python (mark all that apply): fun = 138 138 = hard my_favorite_class = "EECS 138" finally = 2

138 = hard finally = 2

Which of the following are NOT allowed as identifiers in Python (mark all that apply): a_1 a1 1a $a

1a $a

How many inputs does the function below take? def hypotenuse_squared(a, b): return a*a + b*b

2

math.ceil(1.38)

2

determine how many asterisks are printed in each loop below: for data in range(-256, 256): print("*")

256-(-256)= 512

math.sqrt(9) =

3

max(2, min(3, 4))

3

what will be the output of the following code? x = 3 while x > 0: print(x) x = x + 1

3 3 4 4 5 5 6 6 infinite loop

45 + 43 % 5 * (23 * 3 % 2)

45 + 3 * 23 = 114

Pressing return after >> 7**2 at the Python prompt, the value printed is ... 128 49 "7**2" 14

49

13 % 8

5

46 // 9

5

How many items are there in range(-3, 10, 3) ? 3 4 5 0, because it gives an error on negative numbers

5

In Python, what is the value returned by the following built-in function call?: max(-6, 5, 1, 3) 5, since it rightmost on the number line 1, since it is closest to zero 3, since it is the rightmost (greatest index) argument -6, since it has the largest magnitude (aka absolute value) 6, since it is the largest absolute value of all the arguments

5, since it rightmost on the number line

If the variable serum_amount has value 11 and then I execute the statement serum_amount /= 2, serum_amount's value will be ... 22 5.5 5 the previous value 11, since the line will give a syntax error

5.5

what is the value of 26 // 4 ? how would you rewrite the expression if you wished the result to be a floating-point number?

6 ; 26 // float(4)

8 % 13

8

If the variable pop has value 2 and then I execute the statement pop *= 4, pop's value will be ... 16 4 8 the previous value 2, since the line will give a syntax error

8

Write a function that receives a number of seconds and returns the numbers of hours.

Def hour(seconds): Return seconds/3600

write an equivalent of the following code for loop: x = 1 while x < 7: print(x) x += 2

For x in range(1,7,2): print(X)

what does print ("Hi ", "There") do?

Hi There (two spaces)

whta does first_name = "Micheal"; print("Hi,", first_name, "!") do?

Hi, Micheal !

Write a function that takes as inputs the three side lengths of a triangle and returns its area, using Heron's formula:

Import math # Def heronA(a,b,c): s=(a+b+c)/2 #semi-per, A=math.sqrt(s*s-a)*(s-b)*(s-c)) Return A

write a program to sum the following series: 1/3+3/5+5/7+9/11+11/13+...+95/97+97/99

S=0 For i in range (1,98,2): S += i/(i+2) print(S)

After executing ans = (251 % 2 == 1), ans has the value ... 2 True False undefined, since the line will give a syntax error

True

Using functions we have seen in lecture, what is the value of is_perfect_square(max(-3, 0, 2)*abs(-8)) ?

True

13 == 8

false

13<8

false

if x=20 x == 22 what is the output?

false

if x=20 x > 22 what is the output?

false

if x=3 and y=5 x>5 and y>6 what is the output?

false

what are the invalid identifiers in the following: apple, name, four, for, 4th, defcon5, $name, first_name

for, 4th, $name

In the program below, is the function display_greeting being used to return a value, have an effect, or both? def display_greeting(): name = input("What is your name? ") print("Hello,", name) display_greeting()

have an effect

which of the following are python keywords? int, x, y, radius, alif, elif, elf, else, s, str, string

int, elif, else, str

Identify and fix the errors in the following code: for i in range(10) mysum += i

mysum=0 for i in range(10): mysum += i ADD COLON AND DEFINE SUM^

The following is a "Hello, World!" program in Python print("Hello, World!") printf("Hello, World!"); main() { printf("Hello, World!\n"); } print(Hello, World!)

print("Hello, World!")

what does print (1+3+8) do?

prints 12

the argument for trigonometric functions represents an angle in: degrees or radians ?

radians

how do you generate a random integer r such that 0 <= r < 20?

random.randint (0,19)

which of the following is a possible output from random.random() ? 13.8, 0.138, 138.0, 0.38, 0.831, -0.38, 1.38, 83.1

random.random= [0, 1.0] 0.138, 0.38, 0.831

A boolean function implementing is_multiple_of_three with input n might use the following line in its function body: return n*3 == True return n%3 == True return n//3 == 0 return n%3 == 0

return n%3 == 0

what does print ("The answer is", 1+3+8) do?

the answer is 12

13 != 8

true

13 >= 8

true

if x=20 x != 22 what is the output?

true

if x=20 x <= 22 what is the output?

true

if x=3 and y=5 x<5 and y<6 what is the output?

true

if x=3 and y=5 x>5 and y<6 what is the output?

true

write a boolean expression for "x is equal to 3"?

x == 3


Kaugnay na mga set ng pag-aaral

Strategic Management Chapter 1, Honors Strategic Management Exam 1

View Set

CCNA Routing and Switching: Scaling Networks Chapter 2

View Set

Chapter 54: Care of Patients with Musculoskeletal Trauma....

View Set