【问题标题】:Print is invalid Syntax? [Python 3]打印是无效的语法? [Python 3]
【发布时间】:2013-08-27 04:47:17
【问题描述】:

我正在尝试编写一个程序来为视频游戏做一些简单的数学运算,但是我遇到了多个错误。

Print IS 之后的字符串在括号中,因为 Python 3。 如果我尝试为“FCS”输入 1.5 或类似的值,我也会收到“计算错误”

import decimal
print("ARMORED CORE V - FCS SIMULATION")
print("This program will calculate lock times for weapons combined with their FCS in           Armored Core V")
print("----------------------------------------------------------------------------")

#Base Weapon Lock/FCS Lock Percentage (150=1.5)/60
#Seidenbaum at 421 Base Lock
#421/1.5/60 is lock time (4.67 seconds)
#Subcomputer: Base Weapon Lock/FCS Lock Percentage/Subcomp Lock Percentage  (320=3.02)/Second Subcomp/60
#Subcomps: 421/1.5/3.02/60 (1.54 Seconds)
#Dual Subcomps: 421/1.5/3.02/3.02/60 (0.5 Seconds)

while (1 == 1):
    command = input("\nTo begin, type 'compute'\nThen enter your weapon's Base Lock Time\nThen your FCS' Lock Computation\nAnd then how many Subcomputers you have\nyou can also type help [ compute // help ]")
    if command == "help":
        print("\nFollow the instuctions as prompted\n\nI will also display the Lock Times and Subcomp Acceleration for FCSes and Subcomputers")
        print("--FCSes--\nUFC-11 GLANCE - 1.7 Lock Computation\nFCS-09 YASAKANI - 1.05 Lock Computation\nKV-1T2/OTKRYT - 0.75 Lock Computation\nFCS-07/Lr UZUME - 1.8 Lock Computation\nSEHER FCS199 - 1 Lock Computation\nPREDIRE FCS190 - 1.5 Lock Computation\n--SUBCOMPUTERS--\nSUBCOMPUTER USC-1 DHANBAD - 3.02 Lock Improvment\nSUBCOMPUTER SBC-9 TSUKUYOMI - 3.06 Missile Lock Improvement [Enter Normally]")
    if command == "compute":
        baselock = input("\n\nEnter your weapon's Base Lock Time >> ")
        fcs = input("\nEnter your FCS' Lock Computation as a Percentage >> ")
        subcompone = input("\nEnter your first Subcomputer's lock improvment\n Enter '1' if you don't have any subcomps >> ")
        subcomptwo = input("\nEnter your second Subcomputer's lock improvment\n Enter '1' if you don't have a second subcomputer >> ")
        try: 
locktime = float(int(baselock)//int(decimal.decimal(fcs)//int(decimal.decimal(subcompone)//int(decimal.decimal(subcomptwo)//60)
                return(locktime)
                print("Seconds")
        except ValueError:
            print("error in calculation")

【问题讨论】:

  • 我们不知道回溯的样子。从表面上看,你也没有。
  • 疯狂地,Google 找到了您的代码的旧版本 here(我很好奇您指的是哪个视频游戏)。

标签: python math syntax


【解决方案1】:

你忘记了一行结束括号

locktime = float(int(baselock)//int(decimal.decimal('fcs')//int(subcompone)//int(subcomptwo)//60))

另外,我假设这是在函数中并且需要return,但如果返回被击中,print('seconds') 将不会被执行。 无法访问。

【讨论】:

  • 是的。我在最后的声明中说过。应该让它更深刻。谢谢。 :)
猜你喜欢
  • 1970-01-01
  • 2014-04-29
  • 1970-01-01
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2017-11-04
相关资源
最近更新 更多