0
Write a program that reads an integer N and then read N real numbers, separating the smallest and largest, presenting them on the screen.
N = int(input("Digite N: "))
i = 0
ma = 'maior'
me = 'menor'
me = x
while i < N:
x = float(input("Digite um número: "))
ma = x
me < ma
i = i + 1
if x > ma:
ma = x
if x < me:
me = x
print ('O maior valor digitado foi {} e o menor foi {}'.format(ma,me))
In the program, the user is asked to enter an integer value N and then read N real numbers, thus showing the lowest and highest value among those. The point is that I am doing it without using the list method. (beginner programming.) This code works in some tests, but not in others. I know the problem is in the declaration of variables or in the conditions of the functions if. But I do not see/ I can fix these errors.
Please avoid answering only with codes. What may be trivial to you can be complex to other users, so always look to detail the solution as best as possible, including describing it in text.
– Woss
And your solution has a small flaw, because in this case, you cannot make the condition
if ma
orif me
only, since any value that is assessed as false, such as 0.0, does not satisfy it. Consequence of this, for example, if you enter two numbers:[0.0, -1.0]
, the program will rate -1.0 as the largest (link).– Woss
You’re right... I got it right.
– Shoo Limberger