在“正在计算......”之后,程序不会执行任何操作

时间:2018-02-19 01:33:51

标签: python python-3.x

所以这是我计算计算机处理能力的程序的一部分。这个特定的部分旨在找到系统中的瓶颈。如有必要,我可以提供其余的代码。开头的数字(cpus,gpus,rams,hds)是每个部分的分数。执行此代码时,“计算...”消息后没有任何反应。请温柔,我真的很喜欢这个

from termcolor import colored
global cpus
global gpus
global rams
global hds
global type
global typ

cpus = 3.0406
gpus = 1.9893
rams = 0.8817
hds = 1.0364
type = 2
typ = 2

def btlcalc1():
  print(colored("Calculating bottleneck...", "yellow"))
  global bgpus
  global brams
  global bhds
  global bcpus
  if type == "1": #laptop
    bgpus = gpus*3.5
    brams = rams*4
    bhds = hds*5
    bcpus = cpus*2
    btlcalc2()
  if type == "2": #desktop
    btlscore = (gpus*1.75)+(rams*4)+(hds*5)+(cpus*2)
    bgpus = gpus*1.75
    brams = rams*4
    bhds = hds*5
    bcpus = cpus
    btlcalc2()
def btlcalc2():
  if bgpus <= brams and bgpus <= bhds and bgpus <= bcpus:
    gpub = 1
    cpub = 0
    ramb = 0
    hdb = 0
    btlcalc3()
  if bcpus <= brams and bcpus <= bhds and bcpus <= bgpus:
    gpub = 0
    cpub = 1
    ramb = 0
    hdb = 0
    btlcalc3()
  if brams <= bcpus and brams <= bhds and brams <= bgpus:
    gpub = 0
    cpub = 0
    ramb = 1
    hdb = 0
    btlcalc3()
  if bhds <= brams and bhds <= bcpus and bhds <= bgpus:
    gpub = 0
    cpub = 0
    ramb = 0
    hdb = 1
    btlcalc3()
def btlcalc3():
  if gpub == 1:
    print(colored("Your GPU is the bottleneck in your system.", "yellow"))
    print(colored("You could improve your GPU score by overclocking or replacing your GPU.", "orange"))
    thanks()
  if cpub == 1:
    print(colored("Your CPU is the bottleneck in your system.", "yellow"))
    print(colored("You could improve your CPU score by overclocking or replacing your CPU.", "orange"))
    thanks()
  if ramb == 1:
    print(colored("Your RAM is the bottleneck in your system.", "yellow"))
    print(colored("You could improve your RAM score by overclocking, replacing, or installing more or faster RAM.", "orange"))
    thanks()
  if hdb == 1:
    print(colored("Your boot disk is the bottleneck in your system.", "yellow"))
    if typ == 1:
      print(colored("You could improve your boot disk score by replacing your HDD with a faster HDD or an SSD, or by freeing up space.", "orange"))
      thanks()
    if typ == 2:
      print(colored("You could improve your boot disk score by freeing up space.", "orange"))
      thanks()

btlcalc1()
def thanks():
  print("Done")
编辑:我修好了。如果有人想要修改代码。

def btlcalc1():
  print(colored("Calculating bottleneck...", "yellow"))
  global bgpus
  global brams
  global bhds
  global bcpus
  if type == 1: #laptop
    bgpus = gpus*3.5
    brams = rams*4
    bhds = hds*5
    bcpus = cpus*2
    print("Step 1 executed succesfully.")
    btlcalc2()
  if type == 2: #desktop
    btlscore = (gpus*1.75)+(rams*4)+(hds*5)+(cpus*2)
    bgpus = gpus*1.75
    brams = rams*4
    bhds = hds*5
    bcpus = cpus
    btlcalc2()
def btlcalc2():
  global gpub
  global cpub
  global ramb
  global hdb
  if bgpus <= brams and bgpus <= bhds and bgpus <= bcpus:
    gpub = 1
    cpub = 0
    ramb = 0
    hdb = 0
    btlcalc3()
  if bcpus <= brams and bcpus <= bhds and bcpus <= bgpus:
    gpub = 0
    cpub = 1
    ramb = 0
    hdb = 0
    btlcalc3()
  if brams <= bcpus and brams <= bhds and brams <= bgpus:
    gpub = 0
    cpub = 0
    ramb = 1
    hdb = 0
    btlcalc3()
  if bhds <= brams and bhds <= bcpus and bhds <= bgpus:
    gpub = 0
    cpub = 0
    ramb = 0
    hdb = 1
    btlcalc3()
def btlcalc3():
  if gpub == 1:
    print(colored("Your GPU is the bottleneck in your system.", "yellow"))
    print(colored("You could improve your GPU score by overclocking or replacing your GPU.", "yellow"))
    thanks()
  if cpub == 1:
    print(colored("Your CPU is the bottleneck in your system.", "yellow"))
    print(colored("You could improve your CPU score by overclocking or replacing your CPU.", "yellow"))
    thanks()
  if ramb == 1:
    print(colored("Your RAM is the bottleneck in your system.", "yellow"))
    print(colored("You could improve your RAM score by overclocking, replacing, or installing more or faster RAM.", "yellow"))
    thanks()
  if hdb == 1:
    print(colored("Your boot disk is the bottleneck in your system.", "yellow"))
    if typ == 1:
      print(colored("You could improve your boot disk score by replacing your HDD with a faster HDD or an SSD, or by freeing up space.", "yellow"))
      thanks()
    if typ == 2:
      print(colored("You could improve your boot disk score by freeing up space.", "yellow"))
      thanks()

1 个答案:

答案 0 :(得分:1)

type = 2
...
if type == '2'

整数不等于字符串。由于没有条件评估,并且您没有“else”块,代码结束。

在您的条件中添加一些打印调试语句,并添加“else”以查看当您认为条件应该是良好的调试步骤时是否触发。

你应该阅读关于类型转换的方法,以确保在你不控制输入的情况下不会发生这种情况