Computer Science  >  QUESTIONS & ANSWERS  >  Edhesive 4.1 - 4.11 Questions & Answers (All)

Edhesive 4.1 - 4.11 Questions & Answers

Document Content and Description Below

Edhesive 4.1 - 4.11 Questions & Answers 4.1 Lesson Practice We use loops to: - ✔✔Repeat blocks of code 4.1 Lesson Practice Consider the following code: num = int(input("Enter a number, negati ... ve to stop")) while (num >= 0): print ("You entered: " + str(num)) num = int(input("Enter a number, negative to stop")) print ("Done.") What is wrong? - ✔✔The line num = int(input("Enter a number, negative to stop")) should be indented so it is inside the loop 4.1 Lesson Practice - ✔✔Complete the activity. 4.1 Code Practice - ✔✔name = input("Please enter a name, Nope to end ") while (name != "Nope"): print ("Nice to meet you " + name) name = input("Please enter a name, Nope to end ") print ("Done") 4.2 Lesson Practice What is output? Select all that apply. c = 0 while (c < 10): c = c + 5 print (c) - ✔✔5 and 10 4.2 Lesson Practice What is output? Select all that apply. c = 3 while (c < 10): c = c + 2 print (c) - ✔✔5, 7, 9 and 11 4.2 Lesson Practice What is output? c = 1 sum = 0 while (c < 10): c = c + 3 sum = sum + c print (sum) - ✔✔21 4.2 Lesson Practice What should be entered to make the loop print 60 70 80 x = 50 while (x < 80): x = x + ____ print (x) - ✔✔10 4.2 Code Practice: Question 1 - ✔✔sum = 0 count = 0 while (sum <= 100): count +=1 num = int(input("Enter a number: ")) sum += num print("Sum: " + str(sum)) print("Numbers entered: " + str(count)) 4.2 Code Practice: Question 2 - ✔✔pet = input("What pet do you have?") count = 0 while (pet!= "rock"): count +=1 print ("You have a " + str(pet) + " with a total of " + str(count) + " pet(s)") pet = input("Enter pet: ") 4.3 Lesson Practice Consider the following code: x = int(input ("Enter a value: ")) c = 0 sum = 0 while (c < 10): x = int(input ("Enter a value: ")) c = c + 1 sum = sum + x print ("\n\nSum: " + str(sum)) What type of loop is it? - ✔✔Count variable loop 4.3 Lesson Practice This code loops until the user types in 17. It finds and prints the sum of all even numbers entered. n = int(input ("Enter a number, 17 to stop.")) sum = 0 while (n != 17): if (n % 2 == 0): sum = sum + n n = int(input ("Enter a number, 17 to stop.")) print ("Sum: " + str(sum)) This is an example of a(n) ____ loop - ✔✔user input 4.3 Lesson Practice Suppose you change the program in the last problem so the user enters exactly 17 numbers. The loop would then be an example of a(n) _____ loop - ✔✔count variable 4.3 Code Practice: Question 1 - ✔✔age = int(input("How old are you?")) for i in range(1,age+1): print("**HUG**") 4.3 Code Practice: Question 2 - ✔✔i = 3 while i <=21: if i % 3 == 0: print(i) i+=1 4.5 Lesson Practice We use loops: - ✔✔To repeat a section of code 4.5 Lesson Practice What are the two ways to end a loop? (Select two answers.) - ✔✔Count variable Using user input 4.5 Code Practice (dont reccomened using this) - ✔✔i = 0 while True: word=input("Please enter the next word: ") if word == "STOP": break i += 1 print("#{}:You entered{}".format(i, word)) print("All done. {} words entered.".format(i)) 4.6 Lesson Practice Range is an example of a ______________. - ✔✔function 4.6 Lesson Practice The range function must have two parameters? - ✔✔False 4.6 Lesson Practice What list of numbers is created by the following code? range(8) - ✔✔0 1 2 3 4 5 6 7 4.6 Lesson Practice What list of numbers is created by the following code? range(4, 11) - ✔✔4 5 [Show More]

Last updated: 3 years ago

Preview 1 out of 12 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of Edhesive 4.1 - 4.11 Questions & Answers document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$10.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

171
0

Document information


Connected school, study & course


About the document


Uploaded On

Dec 15, 2022

Number of pages

12

Written in

All

Seller


Profile illustration for Nutmegs
Nutmegs

Member since 4 years

607 Documents Sold

Reviews Received
77
14
8
2
21
Additional information

This document has been written for:

Uploaded

Dec 15, 2022

Downloads

 0

Views

 171

Document Keyword Tags


$10.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·