1

I am trying to run this function with the following user input structure but cannot get a correct answer:

def biggest_number(*args):   
   print (max(args))  
   return max(args)

a = (int(x) for x in input().split())

# 3,4,5

print (biggest_number(a))

So far I have tried different type of brackets "(" for tuples and "[" for lists as well as tried converting the strings to integers.

2 Answers 2

1

You can unpack the generator expression using the splat operator:

print (biggest_number(*a))

Although I think you actually want to use a container such as tuple or list since you can only consume the gen. exp. once so that the next call to max after the print gives you an error:

a = [int(x) for x in input().split()]

Or:

a = tuple(int(x) for x in input().split())

However, you still need to unpack since your function does not take the iterables directly.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Moses! Thanks for the answer. here is what I get: ValueError: invalid literal for int() with base 10: '(3,4,5)' with the tuple option
@shaucha Looks like you're giving the wrong input. Your input should be separated by whitespaces.
0

you can try with raw_input() instead of input().

1 Comment

Hi Dharmesh, correct me if I am wrong but looks like raw_input is for Python 2.7 and input is for Python 3.6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.