0
#pylint:disable=E0001
import time

#(V3)
  
def tc():

    print("This small project will help you to easily calculate total scores of students. \nPlease, write sub summative (SS) 1 score.")
    ksq1 = input()
    print("SS1 score is " + ksq1)
    ksq1 = int(ksq1)
 
    print()

    print("Please, write SS2 score.")
    ksq2 = input()
    print("SS2 score is " + ksq2)
    ksq2 = int(ksq2)

    print()

    print("Please, write SS3 score.")
    ksq3 = input()
    print("SS3 score is " + ksq3)
    ksq3 = int(ksq3)

    print()

    print("Please, write big summative (BS) score.")
    bsq = input()
    print("BS score is " + bsq)
    bsq = int(bsq)

    return (ksq1, ksq2, ksq3, bsq)
    

def redoCal():
        ksq1, ksq2, ksq3, bsq = tc()
        
        print("\nCalculating...")

        print()

        time.sleep(1.2)
        
        sumKSQ = (ksq1 + ksq2 + ksq3) / 3
        sumKSQ = str(sumKSQ)
        print("First, we find numerical average of small summative scores. They are added first and then divided by three. \nNumerical average is " + sumKSQ + ".")
        sumKSQ = float(sumKSQ)

        time.sleep(0.5)
        print()

        sumKSQ = sumKSQ * 0.4
        sumKSQ = str(sumKSQ)
        print("Then, we find 40% of numerical average. \nIt is " + sumKSQ + ".")
        sumKSQ = float(sumKSQ)

        time.sleep(0.5)
        print()

        sumBSQ = bsq * 0.6
        sumBSQ = str(sumBSQ) 
        print("Third, we find 60% value of big summative score. \nIt is " + sumBSQ + ".")
        sumBSQ = float(sumBSQ)

        time.sleep(0.5)
        print()

        totalScore = (sumKSQ + sumBSQ)
        totalScore = str(totalScore)
        print("At last, we combine two values by adding. \nTotal score is " + totalScore + ".")
    
theAnswer = ("1")

while theAnswer == ("1" or "Yes" or "yes"):
    tc()
    redoCal()
    print("Would you like to try again? (Yes = 1, no = 0)")
    theAnswer = input()

So, first function (which is tc()) is executed which asks the user for 4 inputs: ksq1, ksq2, ksq3, bsq. At the end of the function I return these variables, because I need their value in the next function (redoCal()). To retrieve the values from the previously mentioned variables, I used ksq1, ksq2, ksq3, bsq = tc() in the next function.

When I execute the program, it asks for 4 inputs as expected. However, when I enter 4 inputs, it asks me again to input 4 values. This is where it gets weird, after inputting 4 values again, the code works as intended and it calculates the score I want. How can I make the first function not repeat itself?

Elshad19
  • 1
  • 2
  • `E0001` is your friend, don't disable it. – JonSG Jan 26 '23 at 16:20
  • 1
    TL;DR: `while theAnswer == ("1" or "Yes" or "yes")` is incorrect. This needs to be something like `while theAnswer.lower() in {'1', 'yes'}` – 0x5453 Jan 26 '23 at 16:21
  • 2
    You are calling `tc()` twice, once in your `while` loop at the end (this call is pointless because you throw away the returned values), and once at the top of `redoCal()`. – jasonharper Jan 26 '23 at 16:21
  • `redoCal()` already calls `tc()`. You don't need the separate call to `tc()` at the bottom of the code. – John Gordon Jan 26 '23 at 16:22
  • I didn't think redoCal() would call it, I thought it would only retrieve the values. Is there any way I can do that? Because in the future, I'd like to recalculate the score without entering 4 values first. – Elshad19 Jan 26 '23 at 16:28
  • Just remove the call to `tc()` in your while loop – MSpiller Jan 26 '23 at 16:30
  • I did it, the code is now working as I want it to, however I don't want my second function to call for the first function, I only want to retrieve the values. How can I do that? Edit: thanks for the help, btw. – Elshad19 Jan 26 '23 at 16:32
  • A question like "how can I use return values of one function as input to another function" would be a good question to ask here on stackoverflow. The question about "why..." has been answered. – MSpiller Jan 26 '23 at 16:49

0 Answers0