Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New Programmer / Program
#1
Hello everyone!
Hope everybody is having a great day.

Well, I am a new programmer and python user, I am trying to apply my knowledge that I got so far into transforming a simple excel spreadsheet into a simple software.
Was doing fine until I had to insert the "IF" function to do some calculations, I thought it would be easy like Excel, however I got stuck here for a few hours already. I need 2 more outputs to "finish" and both depend on this "IF" function.
I ran the program with no problems, as a test, before inserting the "IF" function, and after it I keep getting errors. Tried different methods and "nothing" worked.

Would want to know if someone could chat with me and take a look on the codes I`ve written and look for a solution.

Thank you!
Reply
#2
Good afternoon,

It would help if you posted your code (using the python tag described above) and the full error message you are getting when you run the code.
Reply
#3
Ok hopefully is not that big!
So it I take all out all the IF's and related cells/variables (like "pdrw") it runs.
If include the IF's back I have the following error:

lbOPDO = Label(root, text="OUTPUT DATA",width=35,font=("bold", 14))
^
SyntaxError: invalid syntax

Process finished with exit code 1

import tkinter
import math
from tkinter import *

root = Tk()
menubar = Menu(root)
root.config(menu=menubar)
root.state("zoomed")
root.title("Fluxo Cruzado")

subMenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label="File", menu=subMenu)
subMenu.add_command(label="Save")
subMenu.add_command(label="Save As")
subMenu.add_command(label="Open")
subMenu.add_command(label="Print")
subMenu.add_command(label="Exit")

subMenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label="Help", menu=subMenu)
subMenu.add_command(label="About Us")
subMenu.add_command(label="Version")


########################### IMAGE  ##############################
photo = PhotoImage(file="syngg.png")
label = Label(root, image=photo)
label.pack()

########################### INPUT WINDOW AND INFO #######################################
label_17 = Label(root, text="SYNKICK - DEMO",width=35,font=("bold", 14))
label_17.place(x=570,y=130)

lbgd = Label(root, text="GENERAL DATA",width=35,font=("bold", 14))
lbgd.place(x=100,y=160)

lbwn = Label(root, text="WELL NAME: ",width=20,font=("bold", 10))
lbwn.place(x=25,y=190)

wellnameE = Entry(root)
wellnameE.place(x=340,y=190)

lbRIG = Label(root, text="RIG: ",width=20,font=("bold",10))
lbRIG.place(x=25,y=215)

RIGE = Entry(root)
RIGE.place(x=340,y=215)

lbDate = Label(root, text="DATE (MM/DD/YYYY): ",width=20,font=("bold",10))
lbDate.place(x=25,y=240)

dateE = Entry(root)
dateE.place(x=340,y=240)

lbInPD = Label(root, text="INPUT DATA",width=35,font=("bold", 14))
lbInPD.place(x=100,y=265)

#lbResInf = Label(root, text="Reservoir Information",width=20,font=("bold", 13))
#lbResInf.place(x=180,y=290)

lbRTop = Label(root, text="Well Fluid Density (SCOL): ",width=22,font=("bold",10))
lbRTop.place(x=25,y=315)

rte = Entry(root)
rte.place(x=340,y=315)

lbResB = Label(root, text="Vertical Depth Drilled (m): ",width=22,font=("bold",10))
lbResB.place(x=25,y=340)

rbe = Entry(root)
rbe.place(x=340,y=340)

lbResP = Label(root, text="Estimated Fluid Density (PPG): ",width=25,font=("bold",10))
lbResP.place(x=23,y=365)

rpe = Entry(root)
rpe.place(x=340,y=365)

lbRFV = Label(root, text="Water Depth (m): ",width=22,font=("bold",10))
lbRFV.place(x=25,y=390)

rfve = Entry(root)
rfve.place(x=340,y=390)

lbRFD = Label(root, text="Air Gap (m): ",width=22,font=("bold",10))
lbRFD.place(x=25,y=415)

rfde = Entry(root)
rfde.place(x=340,y=415)

lbppgrb = Label(root, text="Reservoir Top (m): ",width=35,font=("bold",10))
lbppgrb.place(x=10-35,y=440)

ppgrbe = Entry(root)
ppgrbe.place(x=340,y=440)

#lbWInfo = Label(root, text="WELL INFORMATION",width=20,font=("bold", 13))
#lbWInfo.place(x=180,y=465)

lbvdd = Label(root, text="BOP Pressure (psi): ",width=22,font=("bold",10))
lbvdd.place(x=25,y=495)

vdde = Entry(root)
vdde.place(x=340,y=495)

lbDFD = Label(root, text="Diameter (in): ",width=22,font=("bold",10))
lbDFD.place(x=25,y=520)

dfde = Entry(root)
dfde.place(x=340,y=520)

lbWDIAM = Label(root, text="Reservoir K (md):  ",width=22,font=("bold",10))
lbWDIAM.place(x=25,y=545)

wdiame = Entry(root)
wdiame.place(x=340,y=545)

lbmll = Label(root, text="Viscosity (cp): ",width=22,font=("bold",10))
lbmll.place(x=25,y=570)

mlle = Entry(root)
mlle.place(x=340,y=570)

######################## Output WINDOW #################################
def show_answer():
    ################# CALLING INPUT DATA ################################
    wnent = wellnameE.get()
    rigent = RIGE.get()
    dateent = dateE.get()
    restop = rte.get() #Well Fluid Density
    resbase = rbe.get()  #VERTICAL DEPTH DRILLED
    resperm = rpe.get() #Estimated Drilling Fluid Density
    resfvis = rfve.get() #Water Depth
    resfden = rfde.get() #Air Gap
    ppgrb = ppgrbe.get() #Reservoir Top
    vdd = vdde.get() #BOP Pressure
    dfd = dfde.get() #Well Diameter
    wdiam = wdiame.get() #ReservoirK
    mll = mlle.get() #Viscosity

    ######################### CALCULATIONS ###############################
    ####  INSIDE CALCULATIONS  for OUTPUT #####
    n = float(6)
    delta = (float(resbase)-float(ppgrb))/(n-1)    #(VDD-RTOP)/(K-1)

    ####   OUTPUT CALCULATIONS   #####
    comp = round(((float(resbase)-float(ppgrb))/float(n-1)),2)
    sup = round((3.14*(float(dfd)/12)*float(comp)),2)
    wdag = round((float(resfvis)+float(resfden)), 2)
    mlal = round((float(vdd) / (0.17 * float(restop))), 2)
    rmd = round((float(wdag)+float(mlal)+25), 2)
    bpatl = round(float(vdd), 2)
    ppgb = round(((0.17*float(restop)*(float(resbase)-float(wdag)+float(mlal))/(0.17*float(resbase)))), 2)
    bppsi = round(0.17*float(restop)*(float(resbase)-float(wdag)+float(mlal)), 2)
    bpppg = round((float(bppsi)/(0.17*float(resbase))), 2)
    tppsi = round(float(bppsi)-0.17*float(resperm)*(float(resbase)-float(ppgrb)),2)
    tpppg = round(float(tppsi)/(0.1704*float(ppgrb)),2)
    #pdrw = round(float(pff1)-float(pfpcp1),2)

    #Inside Calculations for Table and Extra Info
    #PROFUNDIDADE (depth, prof6>x>prof1)
    prof6 = resbase
    prof5 = float(prof6) - float(delta)
    prof4 = float(prof5) - float(delta)
    prof3 = float(prof4) - float(delta)
    prof2 = float(prof3) - float(delta)
    prof1 = float(prof2) - float(delta)

    #pfpSp - #Pressão Fluido Perf SEM Perda
    pfpsp1 = float(prof1) * 0.17 * float(restop)
    pfpsp2 = float(prof2) * 0.17 * float(restop)
    pfpsp3 = float(prof3) * 0.17 * float(restop)
    pfpsp4 = float(prof4) * 0.17 * float(restop)
    pfpsp5 = float(prof5) * 0.17 * float(restop)
    pfpsp6 = float(prof6) * 0.17 * float(restop)

    #pfpCp-Pressão Fluido Perf COM Perda
    pfpcp6 = bppsi
    pfpcp5 = float(pfpcp6) - 0.17 * (float(prof6) - float(prof5)) * float(restop)
    pfpcp4 = float(pfpcp5) - 0.17 * (float(prof5) - float(prof4)) * float(restop)
    pfpcp3 = float(pfpcp4) - 0.17 * (float(prof4) - float(prof3)) * float(restop)
    pfpcp2 = float(pfpcp3) - 0.17 * (float(prof3) - float(prof4)) * float(restop)
    pfpcp1 = float(pfpcp2) - 0.17 * (float(prof2) - float(prof1)) * float(restop)

    #PFF-PRESSAO FLUIDO FORMACAO
    #pff6 = bpppg

    #if prof5 < ppgrb:
        #pff5 = 0
    #else:
        #pff5 = (float(bpppg)-0.17*float(resperm)*(float(prof6)-float(prof5)))

    #if prof4 < ppgrb:
        #pff4 = 0
    #else:
        #pff4 = (float(pff5)-0.17*float(resperm)*(float(prof5)-float(prof4)))

    #if prof3 < ppgrb:
        #pff3 = 0
    #else:
        #pff3 = (float(pff4)-0.17*float(resperm)*(float(prof4)-float(prof3)))

    #if prof2 < ppgrb:
        #pff2 = 0
    #else:
        #pff2 = (float(pff3)-0.17*float(resperm)*(float(prof3)-float(prof2)))

    #if prof1 < ppgrb:
        #pff1 = 0
    #else:
        #pff1 = (float(pff3)-0.17*(float(resperm)*(float(prof3)-float(prof1)))

    ################## Output DATA #######################################
    lbOPDO = Label(root, text="OUTPUT DATA",width=35,font=("bold", 14))
    lbOPDO.place(x=720,y=160)

    lbcompo = Label(root, text="Comprimento (m): ",width=35,font=("bold",10))
    lbcompo.place(x=15*45,y=190)

    lbcompe = Label(root, text=comp,width=22,font=("bold",10))
    lbcompe.place(x=1000,y=190)

    lbsupo = Label(root, text="Sup Area (m2): ",width=35,font=("bold",10))
    lbsupo.place(x=15*45,y=215)

    lbsupe = Label(root, text=sup,width=22,font=("bold",10))
    lbsupe.place(x=1000,y=215)

    lbwdago= Label(root, text="Water Depth + Air Gap (m): ",width=35,font=("bold",10))
    lbwdago.place(x=15*45,y=240)

    lbwdage = Label(root, text=wdag,width=22,font=("bold",10))
    lbwdage.place(x=1000,y=240)

    lbmlalo = Label(root, text="Mud Line After Loss (m): ",width=35,font=("bold",10))
    lbmlalo.place(x=15*45,y=265)

    lbmlale = Label(root, text=mlal,width=22,font=("bold",10))
    lbmlale.place(x=1000,y=265)

    lbrmdo = Label(root, text="Riser Mud Depth (m): ",width=35,font=("bold",10))
    lbrmdo.place(x=15*45,y=290)

    lbrmde = Label(root, text=rmd,width=22,font=("bold",10))
    lbrmde.place(x=1000,y=290)

    lbbpatlo = Label(root, text="BOP Pressure After TotaL Loss (psi): ",width=35,font=("bold",10))
    lbbpatlo.place(x=15*45,y=315)

    lbbpatle = Label(root, text=bpatl,width=22,font=("bold",10))
    lbbpatle.place(x=1000,y=315)

    lbppgbo = Label(root, text="Pore Pressure Gradient at Base (ppg): ",width=35,font=("bold", 10))
    lbppgbo.place(x=15*45,y=340)

    lbppgbe = Label(root, text=ppgb,width=22,font=("bold",10))
    lbppgbe.place(x=1000,y=340)

    lbCONCO = Label(root, text="Conclusions",width=35,font=("bold",14))
    lbCONCO.place(x=720,y=395)

    lbbppsio = Label(root, text="Bottom Pore Pressure / Gradient (psi): ", width=35, font=("bold", 10))
    lbbppsio.place(x=15 * 45, y=425)

    lbbppsie = Label(root, text=bppsi, width=22, font=("bold", 10))
    lbbppsie.place(x=1000, y=425)

    lbbpppgo = Label(root, text="Bottom Pore Pressure / Gradient (ppg): ", width=35, font=("bold", 10))
    lbbpppgo.place(x=15 * 45, y=450)

    lbbpppge = Label(root, text=bpppg, width=22, font=("bold", 10))
    lbbpppge.place(x=1000, y=450)

    lbtppsio = Label(root, text="Top Pore Pressure / Gradient (psi): ", width=35, font=("bold", 10))
    lbtppsio.place(x=15 * 45, y=475)

    lbtppsie = Label(root, text=tppsi, width=22, font=("bold", 10))
    lbtppsie.place(x=1000, y=475)

    lbtpppgo = Label(root, text="Top Pore Pressure / Gradient (ppg): ", width=35, font=("bold", 10))
    lbtpppgo.place(x=15 * 45, y=500)

    lbtpppge = Label(root, text=tpppg, width=22, font=("bold", 10))
    lbtpppge.place(x=1000, y=500)

    #lbpdrwo = Label(root, text="Pressure Differential Reservoir/Well Res. Top (psi): ", width=35, font=("bold", 10))
    #lbpdrwo.place(x=15 * 45, y=525)

    #lbpdrwe = Label(root, text=pdrw,width=22,font=("bold",10))
    #lbpdrwe.place(x=1000, y=525)

    # lbkfrdo = Label(root, text="Kick Flow Rate (bbl/day): ", width=35, font=("bold", 10))
    # lbkfrdo.place(x=15 * 45, y=425)

    # lbkfrde = Label(root, text=kfrd,width=22,font=("bold",10))
    # lbkfrde.place(x=1000, y=425)

    # lbkfrho = Label(root, text="Kick Flow Rate (bbl/hour): ", width=35, font=("bold", 10))
    # lbkfrho.place(x=15 * 45, y=450)

    # lbkfrhe = Label(root, text=kfrh, width=22, font=("bold", 10))
    # lbkfrhe.place(x=1000, y=450)

btn = Button(root, text = 'Calculate', command=show_answer)
btn.pack(side='bottom')

root.mainloop()
Reply
#4
On line 211, it looks like an uneven number of left/right parenthesis. 7 vs 6
Reply
#5
It looks like compared to the other lines for example
#pff2 = (float(pff3)-0.17*float(resperm)*(float(prof3)-float(prof2)))
the last one has an extra open ( giving a mismatch of open to close brackets
#pff1 = (float(pff3)-0.17*(float(resperm)*(float(prof3)-float(prof1)))
                          ^
Which is giving the
Error:
SyntaxError: invalid syntax
on the following line.
Reply
#6
Hello!
Thanks a lot for helping, what a silly mistake!!
Line 211 was a problem, and got it running now, thanks to you!

However I am getting the wrong value when compared to the excel spreadsheet, I believe something wrong with the formula though.
Gonna keep trying otherwise I will be back on here!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New programmer using GROK AmineLS 2 3,142 Sep-10-2019, 12:25 PM
Last Post: AmineLS
  New Programmer/Need assistance with if statements KayPyth 4 3,117 May-23-2018, 10:25 PM
Last Post: KayPyth

Forum Jump:

User Panel Messages

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