In: Computer Science
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.
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.