Frage

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()

This just results in a syntax-error and i can't figure out why. Your help is much appreciated :-)

War es hilfreich?

Lösung

Since Python 3, print is no longer a statement, but a function. Thus, to use it, you would do print() instead of print.

Python 2.7:

print "Hello world!"

Python 3:

print("Hello world!")

You can read more about the print() function at the docs, which also mentions some parameters you can include, and also how you can use it in python 2.x (from __future__ import print_function)


Also, you're missing a colon after if o1 =="T". May just be a simple typo :).

Andere Tipps

print is a function in Python 3, no longer a statement. Call it like you would any else (simply include parentheses for every call).

Python2.x: print 'some string', Python3.x: print('some string')

You can get the same behaviour in Python2.6 and up by including from __future__ import print_function as the first import of you file.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top