Python Forum
Not getting the return value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not getting the return value
#5
Another way:
#! /usr/bin/env python3
from random import randint

num1 = randint(20, 100)
num2 = randint(20, 100)
num3 = randint(20, 100)

def middle(nums):
    for num in nums:
        if num != min(nums) and num != max(nums):
            return num
print(f'Three numbers: {num1}, {num2}, {num3}')
print(f'Middle number is: {middle([num1, num2, num3])}')
Output:
Three numbers: 62, 37, 84 Middle number is: 62

And still one more
#! /usr/bin/env python3
from random import randint

nums = []
[nums.append(f'{randint(20, 100)}') for i in range(3)]
def middle(nums):
    return [num for num in nums if num != min(nums) and num != max(nums)]

print(f'Three numbers: {", ".join(nums)}')
print(f'The middle number is: {"".join(middle(nums))}')
Output:
Three numbers: 88, 57, 49 The middle number is: 57
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Not getting the return value - by rs74 - Jul-04-2020, 07:39 AM
RE: Not getting the return value - by ndc85430 - Jul-04-2020, 07:39 AM
RE: Not getting the return value - by rs74 - Jul-04-2020, 07:44 AM
RE: Not getting the return value - by ndc85430 - Jul-04-2020, 07:48 AM
RE: Not getting the return value - by menator01 - Jul-05-2020, 01:18 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020