473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why is this Variable not defined?

i am trying to create a simple database with inputs of friends name and age but the lasts variable its not defined apparently
Expand|Select|Wrap|Line Numbers
  1. import pickle
  2.  
  3. class aFriend:
  4.     def __init__(self, name , age):
  5.         self.name = name
  6.         self.age = age
  7.         self.namePlusAge  = []
  8.     def addFriend(self, friend, age):
  9.         self.namePlusAge = age
  10.     def deleteFriend(self, friend, age):
  11.         self.namePlusAge.pop(friend,None)
  12.  
  13.     def addingToDatabase(name):
  14.         database = open("ListOfFriends.txt")
  15.         pickle.dump(name, database, "wb")
  16.         database.close()
  17.     def readNameDataBase():
  18.         read = open("ListOfFriends.txt","rb")
  19.         readData = pickle.load(read)
  20.         for key in newFriend.namePlusAge.keys():
  21.             print(key)
  22.         read.close()
  23.  
  24.     def readAgeDatabase():
  25.         read = open("ListOfFriends.txt", "rb")
  26.         readData = pickle.load(read)
  27.         for key in newFriend.namePlusAge.keys():
  28.             print(key)
  29.         read.close()
  30. def produceMenu():
  31.     print("""
  32.     1 - Add Friend
  33.     2 - Delete a Friend
  34.     3 - List All Friends names
  35.     4 - List All Friend Ages
  36.     5 - Quit
  37.     """)
  38.  
  39. def validateMenu():
  40.     choice = int(input("Select an option"))
  41.     if choice == 1:
  42.         newFriend.addFriend(str(input("what is the friends name?")), input("What is your frriends age?"))
  43.         addingToDatabase(newFriend.namePlusAge)
  44.         produceMenu()
  45.         validateMenu()
  46.     elif choice == 2:
  47.         newFriend.deleteFriend(str(input("What is the friends name you wish to delete?"), input("What is the friends age you wish to delete")))
  48.         addingToDatabase(newFriend.namePlusAge)
  49.         produceMenu()
  50.         validateMenu()
  51.     elif choice == 3:
  52.         readNameDataBase()
  53.         produceMenu()
  54.         validateMenu()
  55.     elif choice == 4:
  56.         readAgeDataBase()
  57.         produceMenu()
  58.         ValidateMenu()
  59.     elif coice == 5:
  60.         quit()
  61.     else:
  62.         produceMenu()
  63.         validateMenu()
  64.  
  65. produceMenu()
  66. validateMenu()
  67. newFriend = aFriend(str(input("Input Your Name: ")), (input("Input Your Age: ")))
  68.  
Feb 25 '13 #1
1 1727
bvdet
2,851 Expert Mod 2GB
When validateMenu() is called, newFriend has not been defined.
Feb 25 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ken Fine | last post by:
I have a Sub which defines a variable. I'm wondering if there's anyway I can get at that variable outside of the context of the Sub -- to pass the variable's contents to another page, for instance....
2
by: MC | last post by:
HI to all, First excuse me but i'm xsl beginner. I'm using XSL to transform an xml file into another. I'm using a Java program for the transformation (TraX API). I would like to recover in...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
16
by: Tom Zych | last post by:
Hi. I've been using code like this: *p++ = 'x'; *p++ = *q++; for a long time now. It works. The code below compiles with no warnings and runs correctly. Even splint doesn't complain about...
3
by: Tom Padilla | last post by:
I am making a map generator and for some bizarre reason I have a variable that will not come in scope. Code snippet: void placeContinents(int NumberOfContinents) { for(int Loop = 0; Loop <...
5
by: jeet_sen | last post by:
Hi, My external javascript test.js contains a variable definition var a = "Hello,world!!"; I dynamically loaded the script test.js using the following fucntion: function loadScript(url) { var...
2
by: Phil Latio | last post by:
Please can someone point me to where the $this variable is discussed in the PHP manual. Done a search of the online manual and the results don't cover it. I use it in ignorance and would like to...
1
by: Meal | last post by:
Is this safe? foo(C2X("")); C2X is a macro defined as #define C2X(str) XStr(str).unicodeForm() XStr is a kind of string processing class. unicodeForm() returns pointer of its member string.
13
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this.html 'this' is defined, as I understand it, for event handlers, but why is it defined, here? Here's the code: <!DOCTYPE html PUBLIC...
1
by: arsha123 | last post by:
How can I change the value of empty session variable with another variable value defined in form. I get value of session value of id from a logon form , that is "". I have defined a variable in form...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.