Question

In: Computer Science

3. Write a program that will accept only 5 numbers from 50 to 100. The program...

3. Write a program that will accept only 5 numbers from 50 to 100. The program should remind the user if an inputted number is not on the range. Compute the sum and average of the 1st and the 5th inputted numbers.

Solutions

Expert Solution

Here is the code using the Python 3 programming language for the given question:

Afte code are the screenshots attached for the proper understanding of the indentation and output of the complied code is also attached.

Explanation of the code is provided using the comments in the code.

In this code, Custom exception has been created.

class Error(Exception):

"""Base class for other exceptions"""

pass

class ValueError(Error):

"""Raised when the input value is too small"""

pass

while True:

nums = list()

#list for storing values

for i in range(1,6):

#taking 5 inputs

number = input("Enter Number between 50 and 100: ")

#using exception handling to check number

try:

number = int(number)

if number > 50 and number < 101:

nums.append(number)

else:

#raising the exception

raise ValueError

except ValueError:

print("Number not in range")

continue

  

if len(nums)==5:

#slicing the list to get the values

a = nums[0]

b = nums[-1]

#printing sum and avgerage

print("Sum of 1st and 5th Numbers is ",a+b)

print("Average of 1st and 5th Number is ",((a+b)/2))

break


Related Solutions

Please write program in C++ format: Write a program to accept five negative numbers from the...
Please write program in C++ format: Write a program to accept five negative numbers from the user. (1) Find the average of the five numbers and display the answer to the standard output. Keep the answer two decimal points - 5 points (2) Output the numbers in ascending order and display the answer to the standard output. - 5 points
Java Write a program that will only accept input from a file provided as the first...
Java Write a program that will only accept input from a file provided as the first command line argument. If no file is given or the file cannot be opened, simply print “Error opening file!” and stop executing. A valid input file should contain two lines. The first line is any valid string, and the second line should contain a single integer. The program should then print the single character from the string provided as the first line of input...
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
Overview: You will write a program that reads up to 100 numbers from a file. As...
Overview: You will write a program that reads up to 100 numbers from a file. As you read the numbers, insert them into an array in ascending order. Specifics: 1A. Write a function called insertIntoSortedArray . i. It should take three arguments - a. myArray[ ] : sorted array that should be able to hold at most 100 integers. b. numEntries : the number of elements inserted so far. c. newValue : the incoming value to be inserted into the...
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6)....
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6). Print the first 3 elements from the list using slice expression. a. Extend this program in a manner that the elements in the list are changed to (6, 9, 12, 15, 18) that means each element is times 3 of the previous value. b. Extend your program to display the min and max value in the list.
MIPS Assembly program: Accept N numbers from the user and sort the N numbers using any...
MIPS Assembly program: Accept N numbers from the user and sort the N numbers using any sorting algorithm. Print both the sorted array and unsorted array. N should be greater than or equal to 10.
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT