CIS115 Week 7 Quiz Latest 2020 December

Question

Dot Image

CIS115 Programming Logic and Design

Week 7 Quiz   

Question 1 (CO 2) Which of the following is not a valid name in python?

  last_name

  lastName

  last name

  lname

Question 2 (CO 3) How many times will “Hello World” be displayed after the following code executes?

num=2

while num<10:

    print(“Hello world”)

    num+=2

  2

  12

  5

  4

Question 3 (CO 1) The following code contains an error, what type of error is it and what line number is it?

1 num=1

2 while num<4

3    print(“num = “, num)

4    num+=1

5 print(“The loop has ended”)

  line 1, syntax error

  line 5, runtime error

  line 4, runtime error

  line 2, syntax error

Question 4 (CO 2) After the following code executes, what will be displayed?

guess=50

if guess<20:

    print(“Too low”)

elif guess>20:

    print(“Too high”)

  Too low

  Too high

  The numbers are equal

  nothing will display

Question 5 (CO 1) Given: x=23, y=15

What is the value of new_num after the following statement executes?

new_num = x%y

  1.5333333

  1

Correct!

  8

  0.533333

Question 6 (CO 1) Which of the following code samples will get a floating point number from the user?

  new_number=float input “Please enter a number: “

  new_number=input(float(“Please enter a number: “))

  new_number=float(input(“Please enter a number: “))

  new_number= input(“Please enter a number: “)

Question 7 (CO 3) What will be displayed after the following loop is run?

sum = 0

for i in range(0, 25, 5):

    sum+=i

print(sum)

  30

  50

  0, 5, 10, 15, 20

  0, 5, 10, 15, 20, 25

Question 8 (CO 6) A return statement

  must be coded within every function

  can be used to return a local variable to the calling function

  can be used to allow the function to modify the value of a global variable

  can only be used once in each function

 Question 9(CO 6) The following code:

if __name__ == “__main__”:

    main();

  is not used

  only works if there is no main method

  is the best way to call the main() function of a program

  is used only in while statements

Question 10  (CO 6) A variable that can only be used within the function that defines it is known as a ______

  local variable

  global variable

  shadow variable

  unknown variable

Question 11  (CO 6) Which of the following statements imports a module?

  export temperature

  import temperature

  from temperature import

  global temperature import

Question 12  (CO 5) To insert the item “chewie” after “solo” in the following list, which of the following methods would you use?

falcon = [“han”, “leia”, “solo”, “yoda”, “luke”]

  falcon.pop(3,”chewie”)

  falcon.remove(3,”chewie”)

  falcon.insert(3,”chewie”)

  falcon.insert(“chewie”, 3)

Question 13 (CO 5) The ______________ method returns the index of the fist occurrence of the specified item in the list

  index(item)

  insert(item)

  pop(item)

  append(item)

Question 14(CO 5) Given the following list, what is the value of names[5]?

names = [“Harry”, “Ron”, “Ginny”, “Draco”, “Rowena” ]

  “Harry”

  “Rowena”

  “Ron”

  None – index error

 Question 15(CO 5) What is the value of the total variable after the following code executes?

prices=[6, 12, 5, 3]

total = 0

i=1

while i<len(prices):

    total+=prices[i]

    i+=1

print(total)

  35

  0

  20

  50

 Question 16(CO 4 and 5) Create a program that will read in a list of test scores from the user and add them to a list. Ask the user in between each score if they want to continue (y/n). Display all of the scores entered and the total score at the end.

Using the code below, put the code in the proper order

SAMPLE OUTPUT:

Welcome to the Test Score Program

Add score:          88.45

Do you want to continue? y or n:              y

Add score:          91.2

Do you want to continue? y or n:              y

Add score:          77.22

Do you want to continue? y or n:              n

The scores were: [88.45, 91.2, 77.22]

Total score:         256.87

Specifications:

The program should accept decimal entries like 52.31 and 15.5.

Assume the user will enter valid data.

The program should round the results to a maximum of two decimal places.

Question 17(CO 4 and 6) Create a program with a function named flipCoin that will flip a coin as many times as the user asks. The flipCoin function should return “heads” or “tails”. The program should continue while the user presses Y. 

SAMPLE OUTPUT:

How many times do you want to flip a coin? 5

You got:  tails

You got:  tails

You got:  tails

You got:  tails

You got:  heads

To continue press Y:  Y

How many times do you want to flip a coin? 3

You got:  heads

You got:  tails

You got:  tails

To continue press Y:  N

SPECIFICATIONS:

You will need to import random in your code

The code to generate a number from 1 to the input sides is: flip = random.randint(1,2)

Use the .upper() command to check upper and lowercase input example: cont = input(“To continue press Y:  “).upper()

Using the code below, select the proper sequence of the code to produce the sample output shown.

Having Trouble Meeting Your Deadline?

Get your assignment on CIS115 Week 7 Quiz Latest 2020 December completed on time. avoid delay and – ORDER NOW

Dot Image

Order Solution Now

Similar Posts