Question

python: find the maximum value from a sequence of positive numbers. you should print out the...

python:
find the maximum value from a sequence of positive numbers. you should print out the maximum number from the sequence.

output:
Keep entering positive numbers.
enter a number:
enter a number:
enter a number:
enter a number:
enter a number:
largest number entered: ...

Homework Answers

Answer #1

Program:

# Takes the length of the list
count = int(input("Enter how many positive numbers you want : "))
print("Keep entering positive numbers")
nums = []
for i in range(count):
    # Taking input of a number from user
    nums.append(int(input("Enter a number: ")))
    
largest = nums[0]
for i in range(1, len(nums)): 
    if nums[i] > largest: # comparing the the largest element
        largest = nums[i]
        
print("Largest number entered :", largest)

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a python script that reads in an unknown number of positive numbers and negative numbers....
Create a python script that reads in an unknown number of positive numbers and negative numbers. These numbers are to be stored in two different collections. Once the user enters a zero value, the script will output all of the values in both collections, separately. Sample Usage/Output: Please enter a positive or negative number (enter a zero to end): 5 Please enter a positive or negative number (enter a zero to end): -7 Please enter a positive or negative number...
1.Draw a flowchart to read 3 numbers: M, K and N and print the largest number...
1.Draw a flowchart to read 3 numbers: M, K and N and print the largest number of them. 2. Devolve an algorithm that allows the user to enter the count of number in a list followed by these numbers. The algorithm should find and output the minimum and maximum numbers in the list. 3. Develop an algorithm that inputs a series of number and output their average.
Using a for loop and range command, print the sequence of numbers from 1 to 20...
Using a for loop and range command, print the sequence of numbers from 1 to 20 (skipping two numbers for each element); that is, your code should print out the numbers 1,4, 7, 10, … (max should not exceed 20). Use x as the variable name
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in the sequence, the next number in the sequence is determined by two simple rules: If the current number n is odd, the next number in the sequence is equal to 3 * n + 1 If the current number n is even instead, the next number in the sequence is equal to one half of n (i.e., n divided by 2) We repeat this...
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
Python: Associate the average of the numbers from 1 to n (where n is a positive...
Python: Associate the average of the numbers from 1 to n (where n is a positive integer value) with the variable avg.
a. Exercise 10-6 from Python Crash Course: One common problem when prompting for numerical input occurs...
a. Exercise 10-6 from Python Crash Course: One common problem when prompting for numerical input occurs when people provide text instead of numbers. When you try to convert the input to an int, you'll get a ValueError. Write a program that prompts the user to input two numbers. Add them together and print the result. Catch the ValueError if either input value is not a number, and print a friendly error message. Test your program by entering two numbers and...
Write a C program that when you type in five numbers, it will print the number...
Write a C program that when you type in five numbers, it will print the number from the smallest one to the largest one.(if you type in 2, 1, 3, 5, 4, the output will be 1, 2, 3, 4, 5 ) You may need more than one function to complete this mission.
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT