Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding error iro a menu
#3
You need to surround code with Python tags. I think I got the indentation correct and the code works for me.
def mainMenu():

    print(' \033[1mMenu program ')
    print(' Press the number next to your choice ')
    print(" 1 - Add Numbers to DataBase ")
    print(" 2 - Print all the Data ")
    print(" 3 - Add Numbers to DataBase ")
    print(" 4 - Add Numbers to DataBase ")
    print(" 5 - Exit the program ")
    while True:
        try:
            selection=int(input('Enter choice: '))
            if selection ==1:
                addnewnames()
                break
            elif selection ==2:
                list()
                break
            elif selection ==3:
                update()
                break
            elif selection ==4:
                delete()
                break
            elif selection ==5:
                print(' You selected 5 - the QUIT key \n Bye Bye!')
                break
            else:
                 print(" INVALID SELECTION. \n Please enter a number between 1 and 3 ")
        except ValueError:
            print('Invalid choice \n Enyer anumber between 1 and 3')
            exit

def addnewnames():
    print('addnewnames')
    input('Hit any key to continue')
    mainMenu()

def list():
    print('list')
    input('Hit any key to continue')
    mainMenu()

def update():
    print ('update')
    input('Hit any key to continue')
    mainMenu()

def delete():
    print ('delete')
    input('Hit any key to continue')
    mainMenu()

mainMenu()
Using list as a variable or function name hides the builtin list() function.
Reply


Messages In This Thread
coding error iro a menu - by Rollo - Sep-26-2020, 03:41 PM
RE: coding error iro a menu - by Rollo - Sep-27-2020, 01:42 PM
RE: coding error iro a menu - by deanhystad - Sep-27-2020, 04:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding error. xflyerwdavis 2 1,217 Oct-07-2023, 07:08 PM
Last Post: deanhystad
  Coding error. Can't open directory EddieG 6 2,508 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Coding Error EddieG 2 1,255 Jul-09-2023, 02:59 AM
Last Post: EddieG
  python coding error isntitzee 1 2,796 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 2,320 Sep-28-2020, 07:57 AM
Last Post: buran
  Adafruit LIS3DH coding error FitDad73 1 2,798 Aug-30-2020, 01:37 AM
Last Post: bowlofred
  Coding error- help FatherYeals 3 53,586 Mar-27-2020, 02:11 PM
Last Post: deanhystad
  name undefined Coding Error Ewilliam51 2 2,877 Feb-06-2020, 12:19 AM
Last Post: Ewilliam51
  coding error bilawal 11 7,931 Dec-07-2019, 05:23 PM
Last Post: DreamingInsanity
  Pyhton Coding Help Needed (very small error) friduk 2 3,317 Oct-23-2019, 08:41 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020