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

ans = True
while ans:
        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
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 for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from :)
User avatar
Posts: 2916
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.
Posts: 2
Joined: Sun Sep 29, 2013 11:28 pm

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 7 guests