Python Forum
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working on nested functions
#1
Hello, I am just toying around and building a script to create network configurations for my CCNP lab..

def mainMenu ():
    print('\n Hello, this is DesignMe, your handy dandy Cisco configuration assistant. This is NetworkNick, How can I help you today?')
    print('\n 1. Base configuration file \n 2. Subnet and IP address allocation \n 3. OSPF network configuration \n 4. Quit \n')
    selection = int(input('Please enter choice below:'))
    try:
        if selection == 1:
            baseRouterConfig()
        elif selection == 2:
            createAddress()
        elif selection == 3:
            networkOSPF()
        elif selection == 4:
            exit
        else:
            print('Invalid choice, please choose from menu options 1, 2,3 or 4.')
            mainMenu()
    except ValueError:
        print('Invalid choice.')
        
def baseRouterConfig():
    hostName()
    UserName()
    thePassword()

def thePassword():
    whatpass = input('\n Would you like a password? ')
    if whatpass.lower().startswith('y'):
        thepassword = False
        while not thepassword:
            reponse = input('What would you like the password to be?')
            secondtime = input('Please retype password..')
            if reponse == secondtime:
                thepassword = True
                return secondtime
    else:
        print('\n You have chosen not to set a password.')
        return

def hostName():
    whatName = False
    while not whatName:
        whatname = input('What is the hostname you would like? ')
        response = input('{} is that correct?'.format(whatname))
        if response.lower().startswith('y'):
            whatName = True
            return whatname

def userName():
    whatName = False
    while not whatName:
        username = input('\n What username would you like? ')
        response = input('{} is that correct? '.format(username))
        if response.lower().startswith('y'):
            whatName = True
            return username


mainMenu()
So I just learned how to use while-loops and functions and my goal right now is to get the main menu to go to the baseRouterConfig() function and then go through the list of functions there.
Reply
#2
A tutorial on how to use functions http://www.tutorialspoint.com/python/pyt...ctions.htm Start at the sectin titled "The Return Statement".
Reply
#3
boxerboy1168 Wrote:my goal right now is to get the main menu to go to the baseRouterConfig() function
Doesn't the code currently execute the baseRouterConfig() function? Do you have issues with this code?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Nested functions: calculation is not performed alexfrol86 4 1,661 Feb-24-2022, 05:32 PM
Last Post: alexfrol86
  Nested functions. Equation equal to zero works in a wrong way alexfrol86 6 1,940 Feb-22-2022, 02:57 PM
Last Post: alexfrol86
  Nested Python functions (Dan Bader's book) Drone4four 4 2,558 Jun-26-2021, 07:54 AM
Last Post: ndc85430
  Getting parent variables in nested functions wallgraffiti 1 2,135 Jan-30-2021, 03:53 PM
Last Post: buran
  Does anyone have unicurses panel functions working on a Windows 10 platform? pjfarley3 0 1,457 Oct-11-2020, 04:41 AM
Last Post: pjfarley3
  Called Functions Not Working WhatAmIDoing09 3 2,552 Jul-12-2019, 07:02 PM
Last Post: ichabod801
  setting parameters for functions and nested functions mepyyeti 5 3,852 Feb-25-2018, 06:42 PM
Last Post: snippsat
  Built in Functions not working mhoneycutt83 4 6,345 Jul-28-2017, 07:39 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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