Python Forum
How to compare two parameters in a function that has *args?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare two parameters in a function that has *args?
#1
Question 
Hello team,

I have the following function

import string
import random

def check_input(*args):
    length = args[0]
    while length <= 0:
        length = int(input("[!] Please insert a positive integer: "))
    number = args[1]
    while length < number:
        number = int(input("[!] Please insert a positive integer: "))


check_input(-1)
check_input(5)
I would like to compare the first argument, in the above example it would ask to input another value instead of -1, and the second argument, in the above example 5.

I am getting the following error:

Error:
IndexError: tuple index out of range
I see *args prints the following when I
print(args)

(-1,)
(5,)
Could you please help me with how can I access the second and the following tuples to come for that function?

Thanks in advance.
Reply


Messages In This Thread
How to compare two parameters in a function that has *args? - by Milan - Mar-26-2023, 05:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  function accepts infinite parameters and returns a graph with those values edencthompson 0 930 Jun-10-2022, 03:42 PM
Last Post: edencthompson
  *args implementation and clarification about tuple status amjass12 10 4,264 Jul-07-2021, 10:29 AM
Last Post: amjass12
  [SOLVED] Good way to handle input args? Winfried 2 2,160 May-18-2021, 07:33 PM
Last Post: Winfried
  How can I write a function with three parameters? MehmetAliKarabulut 1 2,493 Mar-04-2021, 10:47 PM
Last Post: Larz60+
  Two Questions, *args and //= beginner721 8 3,673 Feb-01-2021, 09:11 AM
Last Post: buran
  Parameters aren't seen inside function Sancho_Pansa 8 3,082 Oct-27-2020, 07:52 AM
Last Post: Sancho_Pansa
  RuntimeError: Optimal parameters not found: Number of calls to function has reached m bntayfur 0 6,257 Aug-05-2020, 04:41 PM
Last Post: bntayfur
  Function parameters and values as string infobound 1 1,830 Jul-24-2020, 04:28 AM
Last Post: scidam
  does yield support variable args? Skaperen 0 1,732 Mar-03-2020, 02:44 AM
Last Post: Skaperen
  is there a way: repeat key word args Skaperen 2 2,320 Feb-03-2020, 06:03 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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