Question: PYTHON 1.) Write a program that lets the user input integers one at a time at the keyboard until they type the word done on

PYTHON

1.) Write a program that lets the user input integers one at a time at the keyboard until they type the word done on a line by itself. Print the sum of the values entered. You may assume the user will only enter integers or "done".

For example:

Input Result
3 5 done 8

2.) A variable num has already been defined. Write a while loop which calculates the sum of the perfect squares less than or equal to num. Store the result in the variable acc.

For example, if num is 10, then acc should be 1+4+9=14.

For example:

Test Result
num=5 num= 5 acc= 5

3.)

Use the Design Recipe to write a function, print_histogram, that takes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list.

For example:

Test Result
print_histogram([ 0, 2, 4, 1]) ** **** *
print_histogram([10, 5, 3, -1, 8]) ********** ***** *** ********

4.) Use the Design Recipe to write a function, sum_between, that takes a list and two numbers, a and b, and returns the sum of the numbers in the list that are between a and b (inclusive of both a and b).

For example:

Test Result
print(sum_between([0, 100, 50, 20], 10, 60)) 70
print(sum_between([0, 100, 50, 20], 50, 100)) 150
print(sum_between([-17, -20, -33, 40], -18, 60)) 23

5.) Use the Design Recipe to write a function total_numbers(number_list,weights) that takes a list of numbers and their weights and returns the weighted total of the numbers. Think about what needs to happen before using a loop, during the loop, and after the loop finishes. In this question you are required to use a for loop, and not allowed to use the sum function. If the numbers are [1,2,3] and the weights are [.1,.5,.4] then the weighted total should be 1 * .1 + 2 * .5 + 3 * .4 = 2.3

For example:

Test Result
print(round(total_numbers([1,2,3],[.1,.5,.4]),1)) 2.3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!