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

Write a python program that asks the user about their emails and then check the following:...
Write a python program that asks the user about their emails and then check the following: the entered email is a valid email address (email format is [USERNAME]@[ORGANIZATION].[DOMAIN]. i.e. it should have '@' followed by organization name then at least one '.'and domain) determine if the entered email is a KFUPM email or not (KFUPM emails ends with @kfupm.edu.sa) if the entered email is a valid KFUPM email, determine if it is a freshman student email or not (assume all...
Write a program that will search through an array and check to see if the first...
Write a program that will search through an array and check to see if the first number in the array occurs more than once. If the first number occurs more than once, return true. Otherwise, return false. If the array is empty, return false? You will need to use a variable, loop, and if statement.
Create a program that asks the user to input three numbers and computes their sum. This...
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
Write a python program that asks the user to enter a string containing numbers separated by...
Write a python program that asks the user to enter a string containing numbers separated by commas, e.g., s = '1.23,2.4,3.123', Your program should then calculate and print the sum of the numbers entered. Hint: you need to iterate over the string searching for the commas, i.e. their index. The first number is obtained by slicing between the start of the string and the index of the first comma. The second number is between the last comma and the next...
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 C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
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……..
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: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
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"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT