Midterm 2 - practice 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How many times will the prince statement be executed in the code below when the user enters three in response to the prompt: how many books? iterateb = input("How many book? ") iterateb = int(iterateb) bookstring =' ' For i in range(iterateb): booktitles = input("Book? ") Bookstring=bookstring+' '+booktitle Print(" The books on your list are:"+bookstring)

1

What sequence is generated by range(1, 10, 3)

1 4 7

What is the final value of employee_bonus given value of num_sales is 3 if num_sales == 0: employee_bonus = 0 elif num_sales == 1: employee_bonus = 2 elif num_sales == 2: employee_bonus = 5 else: employee_bonus = 10

10

What will be displayed on screen if the user input is 2008 user_num7 = input()user_num7 = int(user_num7)if user_num7 == 2001:print(user_num7,': Twin Towers')elif user_num7 == 2008:print(user_num7,': Great Recession')elif user_num7 == 2017:print(user_num7,': Hurricane Maria')else:print('No Disasters!')

2008 : Great Recession

What is displayed when the following code is executed? day = 23if day * 10 == 250:ending = "st"elif day * 10 == 240:ending = "nd"elif day * 10 == 230:ending = "rd"else:ending = "th"print(str(day) + ending)

23rd

What is the final value of employee_bonus given value of num_sales is 2 if num_sales == 0: employee_bonus = 0 elif num_sales == 1: employee_bonus = 2 elif num_sales == 2: employee_bonus = 5 else: employee_bonus = 10

5

What will be displayed by the following? For I three in range (50 -21 -10): Print (i3)

50 40 30 20 10 0 -10 -20

What is the value of x after the following code is executed? x = 7If x < 7x = x + 1x = x + 2

9

Which loop is best to use on accessing the elements of a container as one displaying every element in a list

For loop

What is the output given the following inputs: 15 20 0 5 6 entered_value = int(input())minimum_number = entered_valuewhile entered_value > 0: if entered_value < minimum_number:minimum_number = entered_value entered_value = int(input())print('Min value:', minimum_number)

Min value: 15

What should be in the print statement so that the output is:Favorite City: SydneyFavorite City: ParisFavorite City: New YorkFavorite City: Cairo Pre = "Favorite City"cities = ['Sydney', 'Paris', 'New York', 'Cairo']for c in cities:print(__)

Pre+":", c

Which line is not part of the loop body? Answer = 'y' S=input("Song?") Print(s) Answer = input("Continue (y/n)?") Print("thank you for playing")

Print("thank you for playing")

Which range function Will generate the sequence of numbers from 0 to 99

Range(100)

What will be displayed on the screen giving the following code? User_name = ' Valerie' For name_letter and user_name: Print(name_letter) Print("The End!")

V a l e r i e The end!

What will be displayed if the user enters the number 10 in response to the prompt: number? x = int(input('number?'))while x > 6:print(x)print("end")

generates an infinite loop

What would be displayed on screen, given the following code? user_name2 = 'erehwon'for name_letter2 in reversed(user_name2):print(name_letter2)print("The End!")

n o w h e r e The End!

What is displayed when the following code executes?num_items = 7if num_items < 3: print('a')elif num_items > 8: print('f')elif num_items == 6: print('k')print('p')

p


संबंधित स्टडी सेट्स

Unit 8: Global Atmospheric Change

View Set

الوحدة الأولى: المقدمة والمخالفات المرورية والنقاط المرورية

View Set

castillo mid term multiple choice and fill in the blanks

View Set

EXAM 2 Chapter 51: Assessment and Management of Patients with Diabetes Prep-U, EXAM 2 Adult Prep U CH 51 Assessment and Management of Patients With Diabetes part 2

View Set

Module 1 section a: Supply chain management concepts

View Set

Encounters With Life Exercise 22- Kingdom Animalia

View Set

Introduction to International Relations

View Set