Question

In: Computer Science

Create this on Python Write a program that asks for three numbers. Check first to see...

Create this on Python

Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three.

Outputs:

- Enter the first number: 4

- Enter the second number: 78

- Enter the third number: 8

(The largest number is 78.)

Tasks

- Complete the algorithm manually without using any built-in functions to find the largest number on list.

- Revise the program so that all entered values are tracked and the user is prevented from entering a number that’s already been entered.

- Revise the program so that it asks for ten numbers instead of three.

- Revise the program so that it asks for an unlimited number of numbers.

Solutions

Expert Solution

nums = []

def getANum(msg):
    n = int(input(msg))
    while n in nums:
        print('Duplicate number. Enter again: ')
        n = int(input(msg))
    return n

nums.append(getANum('Enter the first number: '))
nums.append(getANum('Enter the second number: '))
nums.append(getANum('Enter the third number: '))

# Now we have all the three numbers
max = nums[0]
for i in range(1, len(nums)):
    if nums[i] > max:
        max = nums[i]

print('The maximum number is:', max)

**************************************************

Please ask each version of the code separately, as they require different code for each section.

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
Using python: Given a string x, write a program to check if its first character is...
Using python: Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True"
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Python Programming Question: Objective: Sum of Numbers. Design a program with a loop that asks the...
Python Programming Question: Objective: Sum of Numbers. Design a program with a loop that asks the user to enter a series of positive numbers. The user should enter "0" (zero) to signal the end of the series. After all the positive numbers have been entered, the program should display their sum. The program should display the following: • Contain proper indentation. • Comments (Blocks or Lines). • Good Variables initializations. • Good questions asking for the parameters of the code....
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT