Devry CIS115 week 7 Quiz October 2020

Question

Dot Image

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

Chapter 3

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

Chapter 3

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  

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: “)

Chapter 2

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.

cont=”y”

while cont==”y”:

# display the results

print(“Total score:”, total)

16

print(“Welcome to the Test score Program”)

total+=item

cont=input(“Do you want to continue? y or n: “)

# get input from the user

# display a welcome message

total = round(total, 2)

scoreList.append(item)

total=0

print(scoreList)

item = float(input(“Add score: “))

scoreList=[]

print(“The scores were: “)

total=0

 1. # display a welcome message

2. print(“Welcome to the Test score Program”)

3. # get input from the user

4. scoreList=[]

5. cont=”y”

6. total=0

7. while cont==”y”:

8. item = float(input(“Add score: “))

9. total+=item

10. scoreList.append(item)

11. cont=input(“Do you want to continue? y or n: “)

12. # display the results

13. print(“The scores were: “)

14. print(scoreList)

15. total = round(total, 2)

16. print(“Total score:”, total)

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.

if(flip==1):

5

cont=”Y”

10

for i in range(0,flips):

13

main();

17

return “heads”

6

import random

else:

7def flipCoin():

if __name__ == “__main__”:

16flips = int(input(“How many times do you want to flip a coin? “))

 

             

12while cont==”Y”:

11

cont = input(“To continue press Y: “).upper()

15#flip coin function returns a heads or tails depending on what is flipped

 2

print(“You got: “,flipCoin())

14

def main():

9

flip = random.randint(1,2)

return “tails”

8

1. import random

2. #flip coin function returns a heads or tails depending on what is flipped

3. def flipCoin():

4. flip = random.randint(1,2)

5. if(flip==1):

6. return “heads”

7. else:

8. return “tails”

9. def main():

10. cont=”Y”

11. while cont==”Y”:

12. flips = int(input(“How many times do you want to flip a coin? “))

13. for i in range(0,flips):

14. print(“You got: “,flipCoin())

15. cont = input(“To continue press Y: “).upper()

16. if __name__ == “__main__”:

17. main();

 

Having Trouble Meeting Your Deadline?

Get your assignment on Devry CIS115 week 7 Quiz October 2020 completed on time. avoid delay and – ORDER NOW

Dot Image

Order Solution Now

Similar Posts