Chapter 4 Algorithm Workbench

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Write a while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate.

again = 'y' while again == 'y': num1 = float(input('Enter a number: ')) num2 = float(input('Enter another number: ')) sum = num1 + num2 print ('The sum of the numbers you entered is', sum) again = input('Do you want to do that again? (y/n): ')

Choose the correct loop that calculates the total of the following series of numbers:130+229+328+...301

denominator = 30 total = 0 for numerator in range(1, 31): value = numerator / denominator total = total + value denominator -= 1 print (total)

Choose the correct for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000

for number in range(0, 1001, 10): print(number)

Choose the correct set of nested loops that display 10 rows of # characters. There should be 15 # characters in each row.

for row in range(10): for column in range(15): print('#', end='') print()

Choose the correct code that prompts the user to enter a positive nonzero number and validates the input.

number = float(input('Enter a positive nonzero number: ')) while number <= 0: print('That is an invalid value.') number = float(input('Enter a positive nonzero number: ')) print ('Thanks!')

Choose the correct code that prompts the user to enter a number in the range of 1 through 100 and validates the input.

number = int(input('Enter a number between 1 and 100: ')) while number < 1 or number>100: print('That is an invalid value.') number = int(input('Enter a number between 1 and 100: ')) print ('Thanks!')

Choose the correct while loop that lets the user enter a number. The number should be multiplied by 10, and the result assigned to a variable named product. The loop should iterate as long as product is less than 100.

product = 0 while product < 100: number = int(input('Enter a number: ')) product = number * 10

Choose the correct loop that asks the user to enter a number. The loop should iterate 10 times and keep a running total of the numbers entered.

total = 0.0 for counter in range(10): number = float(input('Enter a number: ')) total += number print ('The total is', total)

Choose the correct rewrite statements using augmented assignment operators.

x += 1 x *= 2 x /= 10 x -= 100


Kaugnay na mga set ng pag-aaral

3.3-3.4 Survivorship Curves & Carrying Capacity

View Set

Chapter 16 Troubleshooting operating systems. 1002

View Set

ODYSSEY QUOTES BOOKS 14-24 UR WELCOME (samuel butler trans)

View Set

Ch. 6 The Privacy and Security of Electronic Health Information

View Set

Automation Anywhere Advanced RPA Test 1

View Set

Ch.13 Store Layout, Design & Visual Merchandising

View Set

PCR, DNA sequencing, genes (Benzer), Central Dogma, and Prokaryotic Gene Regulation

View Set