Home > Software design >  I need the input fuction to connect to the function i defined
I need the input fuction to connect to the function i defined

Time:07-13

Im having trouble with the input function, I have my code here. I want it to ask you to put the 4 values that are x1,y1,x2 and y2, and then it calculates and returns the finally two values, which are the ARB values and ROI. I know the function i made works fine.

fraction=input("the odds in format as top1,bottom1, top2, bottom2:")
     def arb(x1, y1,x2,y2 ):
        q=((100*y1)/(x1 y1) (100*y2)/(y2 x2))
        print(q)
    
        print("Roi:",100-q, "percent")

CodePudding user response:

So, you have used the input function correctly, you just have not used the result anywhere. It is important to note that input returns a string, so you probably want to modify the result to use it how you want (as 4 separate values).

Sample code:

def arb(args):
    q=((100*args[1])/(args[0] args[1]) (100*args[3])/(args[3] args[2]))
    print(q)

    print("Roi:",100-q, "percent")

# get input as a list of numbers (split the string with commas as delimiters)
fraction = input("the odds in format as top1,bottom1, top2, bottom2:").split(",")

# modify the list so it is a list of integers, so we can do math with the contents, as well as remove whitespace from each string
fraction = [int(number.strip()) for number in fraction]

# now, we can actually pass the list to the function, and use the values the user gave us
arb(fraction)

Output:

the odds in format as top1,bottom1, top2, bottom2:2, 2,3,4
107.14285714285714
Roi: -7.142857142857139 percent

CodePudding user response:

def arb(x1, y1, x2, y2):
    q = (100 * y1) / (x1   y1)   (100 * y2) / (y2   x2)
    print(q)

    print("Roi:", 100 - q, "percent")


x1, x2, y1, y2 = [float(input(f"Enter {var}: ")) for var in ["x1", "x2", "y1", "y2"]]

arb(x1, y1, x2, y2)
  • Related