2 Replies - 269 Views - Last Post: 22 April 2013 - 10:21 PM Rate Topic: -----

#1 wgprodads  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-April 13

Python code issue with names

Posted 20 April 2013 - 09:52 PM

import sys

def mSign():
    
    print ("Please Sign in: ")
    mUser = input("User: ")
    mPass = input("Password: ")

if mUser == "9018a2013" and mPass == "qwerty":
    print ("Access Granted!")
    
elif mUser == "Admin" or "admin" and mPass == "00x00x214":
    print ("Access Granted!")
else:
    print ("Access Denied!")
    print ("Please hit enter to exit...")
    sys.exit(0)

mSign()

def mDirectory():

    mData = ["John Legend" + "Marco Aces" + "Frank Lunar" + "Arron Belkon" + "Kinler Ginger" ]

    myDirect = input ("Select a Directory: ")
    
    print ("  [0] [US Fed. Marshall, Maryland] [1992.35] ")
    print ("  [1] [US Fed. Marshall, Maryland] [1893.18] ")
    print ("  [2] [US Fed. Marshall, Maryland] [1997.72] ")
    print ("  [3] [US Fed. Marshall, Maryland] [1945.14] ")
    print ("  [4] [US Fed. Marshall, Maryland] [1995.20] ")

if myDirect == "0":
    print (mData[0])
    print ("Access Granted!")
elif myDirect == "1":
    print (mdata[1])
    print ("Access Granted!")
elif myDirect == "2":
    print (mdata[2])
    print ("Access Granted!")
elif myDirect == "3":
    print (mdata[3])
    print ("Access Granted!")
elif myDirect == "4":
    print (mdata[4])
    print ("Access Granted!")
else:
    print ("Access Denied! ... Try Again!?")
    myDirect = input ("Select a Directory: ")
    print ("  [0] [US Fed. Marshall, Maryland] [1992.35] ")
    print ("  [1] [US Fed. Marshall, Maryland] [1893.18] ")
    print ("  [2] [US Fed. Marshall, Maryland] [1997.72] ")
    print ("  [3] [US Fed. Marshall, Maryland] [1945.14] ")
    print ("  [4] [US Fed. Marshall, Maryland] [1995.20] ")

if myDirect == "0":
    print (mData[0])
    print ("Access Granted!")
elif myDirect == "1":
    print (mdata[1])
    print ("Access Granted!")
elif myDirect == "2":
    print (mdata[2])
    print ("Access Granted!")
elif myDirect == "3":
    print (mdata[3])
    print ("Access Granted!")
elif myDirect == "4":
    print (mdata[4])
    print ("Access Granted!")
else:
    print (" ERROR 1.0 /// Access Denied!")
    print (" Press enter to exit...")
    sys.exit()

mDirectory()



Is This A Good Question/Topic? 0
  • +

Replies To: Python code issue with names

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2012
  • View blog
  • Posts: 3,035
  • Joined: 21-June 11

Re: Python code issue with names

Posted 21 April 2013 - 12:55 AM

What issues are you having exactly? They're probably related to your indentation, but this will go a lot more smoothly if you tell us what they are.
Was This Post Helpful? 0
  • +
  • -

#3 koborivers  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 19
  • Joined: 08-January 13

Re: Python code issue with names

Posted 22 April 2013 - 10:21 PM

Just a suggestion for the second part of your program. keep your options in a list like
directories = ["  [0] [US Fed. Marshall, Maryland] [1992.35] ",
               "  [1] [US Fed. Marshall, Maryland] [1893.18] ",
               "  [2] [US Fed. Marshall, Maryland] [1997.72] ",
               "  [3] [US Fed. Marshall, Maryland] [1945.14] ",
               "  [4] [US Fed. Marshall, Maryland] [1995.20] "]

myDirect = int(input("Select a Directory: "))

for dir in directories:
    print(dir)

while myDirect > len(directories)-1:

    print ("Access Denied! ... Try Again!?")
    myDirect = input ("Select a Directory: ")
    for dir in directories:
        print(dir)

print(mdata[myDirect])
print("Access granted!")



So instead of writing out each line in the list, let the for loop do it for you. You can then use the input of the user as an index for that list and print out the appropriate message.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1