Computer Science > QUESTIONS & ANSWERS > Edhesive - Unit 4 Test 4 Questions & Answers (All)
Edhesive - Unit 4 Test 4 Questions & Answers What is output? Select all that apply. c = 6 while (c > 0): print (c) c = c - 2 - ✔✔2, 4, 6 Which loop prints the numbers 1, 2...100? - ✔✔c ... = 1 while (c <= 100): print (c) c = c + 1 Ask the user to input a number less than 100. Print all the numbers from that number to 100. Which loop correctly does this? - ✔✔num = int (input("Enter a number between 1 and 100: ")) c = num while (c <= 100): print (c) c = c + 1 Write a program that asks the user for their name and how many times to print it. If I enter Ada and 3 it should print: Ada Ada Ada Which loop correctly does this? - ✔✔name = input("Enter your name: ") num = int (input("Enter a number: ")) c = 1 while (c <= num): print (name) c = c + 1 What does the following loop do? val = 0 total = 0 while (val < 10): v al = val + 1 total = total + val print(total) - ✔✔Prints the sum of the numbers from 1 to 10. Consider the following code: val = 0 while (val < 10): val = val - 1 print (val) What is the error? - ✔✔The loop will not stop since val is counting the wrong direction. For a loop to stop, the loop control variable must ______________. - ✔✔change inside the loop In a(n) __________________ loop, you do not know ahead of time how many times the loop will repeat. - ✔✔user input Which range function will generate a list of all even numbers between 12 and 84 inclusive? - ✔✔range (12, 86, 2) What is output by the following code? for x in range (3, 18): print (x - 2, end=" ") - ✔✔1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Consider the following code: for range (15, 88): print(x) What is wrong with this program? - ✔✔The first line should be for x in range(15, 88): Consider the following code: for i in range (x, y): print (i, end=" ") What values for variables x and y will produce the output below? - ✔✔x = 5 y = 15 What is output by the following code? for x in range (4): for y in range (3): print("*", end=" ") print("")* * * * * ** * ** * * - ✔✔* * * * * * * * * * * * Which of the following is NOT a rule for algorithms? - ✔✔They repeat indefinitely. Information sent to a function is a? - ✔✔parameter Consider the following code: start = int(input("Enter the starting number: ")) stop = int(input("Enter the ending number: ")) x = -5 sum = 0 for i in range (start, stop, x): sum = sum + i print (sum) What is output if the user enters 18 then 13? - ✔✔18 Consider the following code: start = int(input("Enter the starting number: ")) stop = int(input("Enter the ending number: ")) x = 6 for i in range (start, stop, x): print (i, end=" ") What is output if the user enters 12 then 36? - ✔✔12 18 24 30 What is output by the following code: for x in range (8, 16): print (x * 2, end=" ") - ✔✔16 18 20 22 24 26 28 30 Consider the following code: for x (7, 10): print (x) What is wrong with the program? - ✔✔The first line should be for x in range(7, 10):. When do you use a for loop instead of a while loop? (There may be more than one answer.) - ✔✔~When there is a defined start and end. ~You know how many times you want the loop to run. [Show More]
Last updated: 3 years ago
Preview 1 out of 5 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Dec 15, 2022
Number of pages
5
Written in
All
This document has been written for:
Uploaded
Dec 15, 2022
Downloads
0
Views
154
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·