Python menu

This is the place for queries that don't fit in any of the other categories.

Python menu

Postby 3therk1ll » Sun Sep 29, 2013 11:32 pm

Hey guys, brand newbie to Python.
I have done a fair bit of bash before but just getting started here.
Trying to get a basic menu to work, but all it ever prints in teh last statement...

Code: Select all
#!/usr/bin/python

ans = True
while ans:
        print("""
        1. Make a File
        2. Read a file
        3. Ping a website

        Press enter to quit
        """)
        ans=input("Enter choice: ")
        if ans =="1":
                print("\nWe will now make a file...")
        elif ans =="2":
                print("We wil now read a file.")
        elif ans =="3":
                print("\nWe will now ping a website")
        elif ans !="":
                print("\nNot a valid choice")


Regardless of input it only ever prints, "Not a valid choice"
Last edited by Mekire on Sun Sep 29, 2013 11:46 pm, edited 1 time in total.
Reason: First post lock
3therk1ll
 
Posts: 2
Joined: Sun Sep 29, 2013 11:28 pm

Re: Python menu

Postby micseydel » Mon Sep 30, 2013 12:27 am

It looks like you're using code written for Python 3 but in a Python 2 interpreter. Otherwise, replace input() with raw_input() for Python 2.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1372
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Python menu

Postby 3therk1ll » Mon Sep 30, 2013 12:43 am

Cheers mate, that fixed it.
3therk1ll
 
Posts: 2
Joined: Sun Sep 29, 2013 11:28 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], W3C [Linkcheck] and 2 guests