In python please..
Problem 4 (Tracking Statistics – Part 1)
Write a program that repeatedly asks the user to enter an integer
until they want to quit
(e.g., by entering ‘q’). The program should then print the largest
number entered, the
smallest number entered, the average of all numbers entered, the
number of positive
numbers entered, and the number of negative numbers entered (0
should not count as
positive or negative).
Problem 5 (Tracking Statistics – Part 2)
Copy your solution from Problem 4 to start this problem. Now,
instead of having the
user enter the set of numbers, ask the user to enter a filename.
The program should
then read all the numbers from the specified file and output the
same data as Problem
4. You can assume the filename entered by the user specifies a file
that has a single
integer value on each line.The numbertest-resuts.txt file on
includes the
correct values you should see for each file.
Here's one file:
-57 13 46 -59 0 32 27 49 11 -12 -10 -42 -39 9 -34 17 70 -47 -27 70 72 41 -39 18 16 -21 -31 26 68 8 56 -56 44 24 -3 -14 34 52 -23 50 -35 -47 41 21 7 49 12 25 58 -7 8 34 -51 32 70 63 -24 31 25 -33
code:
def main():
n = input("Enter your number(q to quit) : ")
if n!='q' and n!='Q':
maximum = int(n)
minimum = int(n)
count = 0
sum_of_values = 0
positive = 0
negative = 0
while n!='q' and n!='Q':
n = int(n)
if n > maximum:
maximum = n
if n < minimum:
minimum = n
if n > 0:
positive+=1
if n < 0:
negative+=1
sum_of_values+=n
count+=1
n = input("Enter your number(q to quit) : ")
print("Maximum value : ",maximum)
print("Minimum value : ",minimum)
print("# positive values : ",positive)
print("# negative values : ",negative)
print("Average of values : ",sum_of_values/count)
main()
code:
def main():
filename = input("Enter file name : ")
file = open(filename, "r")
count = 0
sum_of_values = 0
positive = 0
negative = 0
for line in file:
if count == 0:
maximum = int(line)
minimum = int(line)
n = int(line)
if n > maximum:
maximum = n
if n < minimum:
minimum = n
if n > 0:
positive+=1
if n < 0:
negative+=1
sum_of_values+=n
count+=1
print("Maximum value : ",maximum)
print("Minimum value : ",minimum)
print("# positive values : ",positive)
print("# negative values : ",negative)
print("Average of values : ",sum_of_values/count)
main()
In python please.. Problem 4 (Tracking Statistics – Part 1) Write a program that repeatedly asks...
Write a python program that repeatedly asks the user to input a pair of integers. The program should record the largest number of each pair into a list. The program should keep asking the user to input pairs of numbers until the user enters -1 for the first number. At this point the program should print the list on a single line, with each value separated by a space and then stop. Example of expected behaviour: Please enter first number:...
Using loops, write a C# program that asks the user to enter repeatedly an integer number, it stops when the user enters -1, then the program should display how many numbers were entered, their the sum and their average
Write a c++ complete program to meet the specifications. The program should prompt the user for a positive integer. The program should print a message whether the integer is even or odd. The looping should end when the user enters a negative number. The negative number will not be tested for even or odd. The program will print out a message of how many numbers were entered (not counting the negative number) and how many even and odd numbers were...
Write a Java program that contains a method named ReadAndFindMax. The argument to this method is the filename (of String type). The method opens the file specified in the method argument filename and then reads integers from it. This file can contain any number of integers. Next, the method finds the maximum of these integers and returns it. The main method must first ask the user to enter the filename; then call ReadAndFindMax method with the entered filename as an...
Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...
Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...
Please answere using python language codes. Write a program to print out Collatz sequence for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows: If previous number is odd, the next number is 3 times the previous, plus 1. If previous number is even, the next number is half of the previous According to Collatz proposition, the sequence ultimately reaches 1...
In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...
Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers. The number n to test the file numbers. Output to the console: The...