我的代码出了什么问题?我是Python 3.3的新手

use*_*630 0 python syntax syntax-error python-3.x text-based

def start():
    import os
    os.system("cls")
    print "*A Wise man once said “Be the change that you wish to see in the world.” This is the idea you have decided to live by and strive for in your quest for making a better world. You are Noah Vis, CEO of the tech giant GAIA and currently the richest man in the world, surpassing the likes of Bill Gates and Waren Buffet by a great margin. Born into a life of modest privilege in the state of Washington, you rapidly asserted your engineering and scientific abilities to build a global technological empire. Your first breakthrough was the F.E.H.C (Fusion Energy Hydrogen Collider). Producing sustainable energy by mashing the two hydrogen isotopes, deuterium and tritium, together at such high energies that they combiine into one atom. After the fusion, you produce a helium and a free neutron. The critical part being that helium+neutron has less mass than deuterium+tritium, and the mass is converted into purge energy. That energy is then captured as heat and used to run a traditional steam-driven turbine. This invention, emerging just as the world's oil supplies reach a critical low, becomes essential. As the middle east decended into conflict, the rest of the world rebuilded using your patents and products. For the most part, people are grateful. Still focused on making the world better, your focus turns. Do you...*"

    print "*[L]ook to the poverty of Africa as the greatest remaining blight on Earth, and resolve to try to bring it to an end, or [T]HIS HAS YET TO BE WRITTEN*"

    o1 = (input('>>'))
    if o1 =="L":
        print "*THIS IS NOT WRITTEN YET*"
    if o1 =="T"
        print "*THIS IS NOT WRITTEN YET*"
        os.system("pause >Nul")

def menu ():
    print "Menu\n"
    print "(1)Start"
    print "(2)Exit\n\n"
    choice = (input('>>'))
    if choice=="1":
        start()
    if choice=="2":
        quit()

menu()
Run Code Online (Sandbox Code Playgroud)

这只会导致语法错误,我无法弄清楚原因.非常感谢您的帮助 :-)

Ter*_*ryA 5

从Python 3开始,print不再是一个声明,而是一个函数.因此,要使用它,你会做print()而不是print.

Python 2.7:

print "Hello world!"
Run Code Online (Sandbox Code Playgroud)

Python 3:

print("Hello world!")
Run Code Online (Sandbox Code Playgroud)

您可以在docs中阅读有关该print()函数的更多信息,其中还提到了您可以包含的一些参数,以及如何在python 2.x()中使用它.from __future__ import print_function


此外,你错过了冒号if o1 =="T".可能只是一个简单的错字:).

  • 是的:)`__future__`导入被称为`print_function` btw,而不是`print_statement`;) (2认同)