第64行的python语法错误(对此真的很新)

时间:2018-02-16 00:58:14

标签: python syntax

所以我对python和编码一般都很陌生,但我正在尝试制作一个程序,根据每个部分及其规格来计算计算机的处理能力和功耗。但是,我一直收到这条消息。

Traceback (most recent call last):
  File "python", line 64
    drive()
        ^
SyntaxError: invalid syntax

我只是不明白。我的代码出了什么问题?我知道这是垃圾,但我是新手,还在学习。这可能是一件非常简单的事情。

这里的任何方式都是代码:

  def start():
    print("* Welcome to Spicy's Processing Power / TDP Calculator! (SPPTDPC) *")
    print("* Version 0.0.5 *")
    print("** This program is still in alpha stage and isn't perfect **")
    print("If you are unsure about one of the questions, look up the specs of the part on a website like PCPartPicker or TechPowerUP")
    cpu()
def cpu():
    global r
    global cpus
    global cputdp
    name = input("What is the name of your processor?")
    c = float(input("How many cores does the "+name+" have?"))
    t = float(input("How many threads does the "+name+" have?"))
    l1 = float(input("How much L1 cache (in total) does the "+name+" have in KB?"))
    l2 = float(input("How much L2 cache (in total) does the "+name+" have in MB?"))
    l3 = float(input("How much L3 cache (in total) does the "+name+" have in MB?"))
    g = float(input("What is the clock speed (in GHz) of the "+name+"?"))
    n = float(input("What is the fabrication process of the "+name+" in nm?"))
    r = float(input("What type of RAM does the "+name+" use? Enter 3 for DDR3, 4 for DDR4, etc."))
    cputdp = float(input("What is the TDP of the "+name+"?"))
    cpus = (c+t+g+r+l2+(l1/100)+(.3*l3))/n #CPU Processing Power Formula
    print("** The "+name+" has a score of "+str(cpus)+". **")
    ram()
def ram():
  global rtdp
  global rams
  g = float(input("How much RAM does your system have (in GB?)"))
  m = float(input("What is the speed of your slowest installed DIMM? (in MHz)"))
  rtdp = float(input("How many DIMMs do you have installed?"))
  rtdp = rtdp*4
  rams = ((r+(m/500))*g)/150 #RAM Processing Power Formula
  print("** Your RAM score is "+str(rams)+". **")
  gpu()
def gpu():
  gputest()
  print("** The "+gpuname+" has a score of "+str(gpus)+". **")
  gputdp = float(input("What is the TDP of the "+gpuname+"?"))
def gputest():
    global gpuname
    global memtyp
    global gputdp
    gpuname = input("What is the name of your GPU?")
    memtyp = int(input("What type of memory does your GPU use? 0 for GDDR, 1 for HBM"))
    gputdp = float(input("What is the TDP of your GPU?"))
    if memtyp == 0:
        gddr()
    if memtyp == 1:
        hbm()
    else:
      print("Error: Please enter either 0 or 1.")
      gputest()
def gddr():
  global gpus
  gc = float(input("How many cores does the "+gpuname+" have?"))
  gt = float(input("How many TMUs does the "+gpuname+" have?"))
  go = float(input("How many ROPs does the "+gpuname+" have?"))
  gm = float(input("How much memory (in MB) does the "+gpuname+" have?"))
  gr = float(input("What type of memory does the "+gpuname+" have? Enter 3 for GDDR3, 5 for GDDR5, and 8 for GDDR5X (to account for its additional data rate)"))
  gb = float(input("What is the bus width of the "+gpuname+"?"))        
  gg = float(input("What is the clock speed of the "+gpuname+" in GHz?"))
  gmg = float(input("What is the effective memory speed of the "+gpuname+" in MHz?"))
  gn = float(input("What is the fabrication process of the "+gpuname+" in nm?"))
  gpus = (((gc/400)+(gt/25)+(go/10)+(gm/1000)+(gb/30)+(gg*2)+(gmg/1000))*((gr/gn)/25) #GDDR GPU Processing Power Formula
  drive()
def hbm():
  global gpus
  hgc = float(input("How many cores does the "+gpuname+" have?"))
  hgt = float(input("How many TMUs does the "+gpuname+" have?"))
  hgo = float(input("How many ROPs does the "+gpuname+" have?"))
  hgm = float(input("How much memory (in MB) does the "+gpuname+" have?"))
  hgr = float(input("What type of HBM does the "+gpuname+" have? Enter 1 for HBM, 2 for HBM2, etc."))
  hgb = float(input("What is the bus width of the "+gpuname+"?"))       
  hgg = float(input("What is the clock speed of the "+gpuname+" in GHz?"))
  hgmg = float(input("What is the effective memory speed of the "+gpuname+" in MHz?"))
  hgn = float(input("What is the fabrication process of the "+gpuname+" in nm?"))
  gpus = (((hgc/400)+(hgt/25)+(hgo/10)+(hgm/1000)+(hgb/250)+(hgg*2)+(hgmg/150))/((hgr/hgn)/25) #HBM GPU Processing Power Formula
  drive()
def drive():
  print("** The "+gpuname+" has a score of "+str(gpus)+". **")
  global typ
  typ = float(input("Is your boot drive an HDD or SSD? Enter 1 for HDD, 2 for SSD."))
  if typ == 1:
    hdd()
  if typ == 2:
    ssd()
def hdd():
  global free
  global total
  global hds
  rpm = float(input("What is the RPM of your HDD?"))
  free = float(input("How much storage is available (not filled) on your boot drive (in GB)"))
  total = float(input("What is the total amount of storage on your boot drive (in GB)"))
  freespace()
  hds = (((1/p)*100)*(rpm/1000))/12 #HDD Processing Power Formula
  drivetdp()
def ssd():
  global free
  global total
  global hds
  free = float(input("How much storage is available (not filled) on your boot drive (in GB)"))
  total = float(input("What is the total amount of storage on your boot drive (in GB)"))
  freespace()
  hds = ((((1/p)*100)*5)*typ)/12 #SSD Processing Power Formula
  drivetdp()
def freespace():
  global p
  p = (free/total)*100
  print("* Your boot drive is "+str(p)+"% free. *")
def drivetdp():
  global ssdtdp
  global hddtdp
  ssdtdp = float(input("How many SSDs do you have installed in your system?"))
  ssdtdp = ssdtdp*3.25
  hddtdp = float(input("How many HDDs do you have installed in your system?"))
  hddtdp = hddtdp*8
  print("** Your boot drive's score is "+str(hds)+". **")
  final()
def final():
  global fns
  global tdp
  global psu
  print("Calculating final score...")
  fns = (cpus+gpus+hds+rams) #Final Score Formula
  print(str(fns))
  dvdtdp = float(input("How many optical drives do you have installed?"))
  dvdtdp = dvdtdp*20 #1 ODD draws around 20 watts
  fantdp = float(input("How many case fans do you have installed? (counting CPU cooler)"))
  fantdp = fantdp*5 #1 120mm fan draws around 5 watts
  usbtdp = float(input("How many USB ports does your computer have? (in total)"))
  usbtdp = usbtdp*2.5 #USB can only pull 2.5 watts
  tdp = (((cputdp+gputdp)*(4/5))+rtdp+hddtdp+ssdtdp+dvdtdp+fantdp+usbtdp)+50 #estimated max load TDP equation, the +50 watts is for the motherboard
  psu = cputdp+gputdp+rtdp+hddtdp+ssdtdp+dvdtdp+usbtdp+50 #max spec TDP equation
  print("** Your final score is... **")
  print(str(fns))
  print("** Your predicted maximum load wattage is... **")
  print(str(tdp))
  print("** I would recommend using a power supply of at least "+str(psu)+" watts. **")
  print("Thank you for using SPPC!")
  print("Copyright NFR 2018")
start()
again = input("Do you want to use the calculator again? Y/N")
if again == "Y":
    start()
#Copyright NFR 2018

2 个答案:

答案 0 :(得分:1)

这一行:

 gpus = (((gc/400)+(gt/25)+(go/10)+(gm/1000)+(gb/30)+(gg*2)+(gmg/1000))*((gr/gn)/25)

缺少一个括号,它应该是:

gpus = (((gc/400)+(gt/25)+(go/10)+(gm/1000)+(gb/30)+(gg*2)+(gmg/1000))*((gr/gn)/25))

答案 1 :(得分:1)

将来只会粘贴相关的代码行而不是整个文件。错误在第64行,所以一个好主意是将4-5行粘贴到65以上然后指示第64行。

现在回答这个问题。在第63行,你有一个额外的开括号,永远不会被关闭。如果你照看等号,你打开三个括号。如果你按照所有的开口和关闭,有一个从一开始仍然打开。