-1

Suppose researchers have analyzed data from the spread of a particular disease and have fit the data to the following model, which predicts the number of people in a small population who will have the disease on day t:

()=20^3-t^4/100

Define a function named max_infection that will compute () for 20 days (i.e. for 1≤≤20) and return two values:

  • the day at which the most people are infected, and

  • the number of people infected on that day.

I need to write a function that will return two values but I am not sure how to do that. I am new to python and am completely confused. I know I need to define the function first but even that in itself is still confusing to me

There are no arguments passed to this function. The expected answer is 16.875 people infected on day 15.

Rizzloe
  • 1
  • 2
  • You can read [here](https://docs.python.org/3.3/tutorial/datastructures.html#tuples-and-sequences) about _tuples_. You can't return two values, but returning a tuple with two elements is just as good. – Amadan Feb 15 '19 at 07:48

1 Answers1

-1

I hope this helps you understand what you want to achieve:

def fun_a():
    a = 23
    b = 24
    return a ,b


c ,d = fun_a()
print(c, d)

OUTPUT:

23 24

Also another way to achieve this can be using a list or tuple to return the data.

Here is how you return a tuple:

class Test: 
    def __init__(self): 
        self.str = "stackoverflow"
        self.x = 20   

# This function returns an object of Test 
def fun(): 
    return Test() 

# Driver code to test above method 
t = fun()  
print(t.str) 
print(t.x)

OUTPUT:

stackoverflow
20

Happy Coding.

Devanshu Misra
  • 773
  • 1
  • 9
  • 28