lundi 21 mai 2018

python nested for loop doesn't give all outputs

Okay so this is my code im supposed to get 16 outputs where each of the values from each of the for loops are multiplied each other but for some reason i'm getting only 4 out puts where only the 4000 value of K is being multiplied with all values of D. can some one tell me where i went wrong?

    def main():
            for i in range(0,4):
                    for j in range(0,4):
                            if j==0:
                                    K=1000
                            elif j==1:
                                    K=2000
                            elif j==2:
                                    K=2500
                            else:
                                    K=4000


                    if i==0:
                            D=2
                    elif i==1:
                            D=4
                    elif i==2:
                            D=5.5
                    else:
                            D=10

                    print("The year with depth",D,"and K as",K,"is",K*D)


    main()

Aucun commentaire:

Enregistrer un commentaire