[Tutor] creat a program that reads frequency of words in file

2015-06-01 Thread Stephanie Quiles
Hello. i need serious help. i am a very very new python programmer. I have 
never done any code in my life. I am lost with these assignments for a class i 
am taking. I hope someone can assist. below is what i have so far which i know 
is incorrect. my question is how do i create a dictionary and save the words 
plus counts to it? i created an empty dictionary and i understand the program 
should read the entire file and create dictionary and store the data into it. 
but the only way i could get it to run at all was in the way you see below. i 
don’t think anything is actually being saved into the dictionary. i am so lost…


“”" Word Frequency

Write a program that reads the contents of a text file. The program should 
create a dictionary in which the
keys are the individual words found in the file and the values are the number 
of times each word appears.
for example, if the word 'the' appears 128 times, the dictionary would contain 
an element with 'the'
as the key and 128 as the value. the program should either display the 
frequency of each word or create a second file
containing a list of each words and its frequency.   """


def main():
dict = {}
count = 0
text = input('enter word: ')
data = open("words.txt").readlines()
for line in data:
if text in line:
count += 1
print("This word appears", count, "times in the file")



main()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] creating a dictionary for capital quiz program

2015-06-02 Thread Stephanie Quiles
Good evening, 

As you may have noticed i am really struggling with functions and dictionaries. 
I need to figure out why this program is allowing me to continue entering 
incorrect data instead of telling me my answer is incorrect. also at the end 
it’s not tallying the incorrect/correct responses properly. please any help 
would be appreciated. 

Write a program that creates a dictionary containing the U.S. States as keys 
and their
capitals as values.
(Use the internet to get a list of the states and their capitals.)
The program should then randomly quiz the user by displaying the name of a 
state and asking
the usr to enter that state's capital.
The program should keep a count of the number of correct and incorrect 
responses.
(As an alternative to the US states, the program can use the names of countries 
and
their capitals.)"""

import pickle


def main():

right = 0
wrong = 0
capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', \
 \
   "Arizona": 'Phoenix', \
 \
   'Arkansas': 'Little Rock', 'California': 'Sacramento', \
 \
   'Colorado': 'Denver', \
 \
   'Connecticut': 'Hartford', 'Delaware': 'Dover', \
 \
   'Florida': 'Tallahassee', \
 \
   'Georgia': 'Atlanta', 'Hawaii': 'Honolulu', \
 \
   'Idaho': 'Boise', \
 \
   'Illinois': 'Springfield', 'Indiana': 'Indianapolis', \
 \
   'Iowa': 'Des Moines', \
 \
   'Kansas': 'Topeka', 'Kentucky': 'Frankfort', \
 \
   'Louisiana': 'Baton Rouge', \
 \
   'Maine': 'Augusta', 'Maryland': 'Annapolis', \
 \
   'Massachusetts': 'Boston', \
 \
   'Michigan': 'Lansing', 'Minnesota': 'Saint Paul', \
 \
   'Mississippi': 'Jackson', \
 \
   'Missouri': 'Jefferson City', 'Montana': 'Helena', \
 \
   'Nebraska': 'Lincoln', \
 \
   'Nevada': 'Carson City', 'New Hampshire': 'Concord', \
 \
   'New Jersey': 'Trenton', \
 \
   'New Mexico': 'Santa Fe', 'New York': 'Albany', \
 \
   'North Carolina': 'Raleigh', \
 \
   'North Dakota': 'Bismarck', 'Ohio': 'Columbus', \
 \
   'Oklahoma': 'Oklahoma City', \
 \
   'Oregon': 'Salem', 'Pennsylvania': 'Harrisburg', \
 \
   'Rhode Island': 'Providence', \
 \
   'South Carolina': 'Columbia', \
 \
   'South Dakota': 'Pierre', 'Tennessee': 'Nashville', \
 \
   'Texas': 'Austin', 'Utah': 'Salt Lake City', \
 \
   'Vermont': 'Montpelier', \
 \
   'Virginia': 'Richmond', 'Washington': 'Olympia', \
 \
   'West Virginia': 'Charleston', \
 \
   'Wisconsin': 'Madison', 'Wyoming': 'Cheyenne'}

for k in capitals.keys():
state = input('Enter the capital of '+k+' :')
if state.upper() == capitals[k].upper():
right += 1
print('Correct')
else:
wrong += 1
print('Incorrect')
choice = input('Do you want to play again y/n: ')
if choice.upper() == 'N':
print('end of game')
else:
choice.upper() != 'Y'
print("invalid choice")

print('Number of correct answers is: ', right)
print("Number of incorrect answers is:", wrong)

main()



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creat a program that reads frequency of words in file

2015-06-02 Thread Stephanie Quiles
thanks on the help. I am now stuck on this program for quizzing on state 
capitals. Do you mind taking a look please? I can’t get it to tell me the 
answer is incorrect it just keeps asking me for capitals whether the answer is 
right or wrong. It also is not giving me correct counts for correct and 
incorrect answers. Any help would be appreciated. Not sure if i turned HTML. my 
laptop is fairly new and I’m still assimilating to iOS. Please let me know if 
the code is hard to read. 

Thanks 

___
Write a program that creates a dictionary containing the U.S. States as keys 
and their
capitals as values.
(Use the internet to get a list of the states and their capitals.)
The program should then randomly quiz the user by displaying the name of a 
state and asking
the usr to enter that state's capital.
The program should keep a count of the number of correct and incorrect 
responses.
(As an alternative to the US states, the program can use the names of countries 
and
their capitals.)"""

import pickle


def main():
right = 0
wrong = 0
capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', \
 \
   "Arizona": 'Phoenix', \
 \
   'Arkansas': 'Little Rock', 'California': 'Sacramento', \
 \
   'Colorado': 'Denver', \
 \
   'Connecticut': 'Hartford', 'Delaware': 'Dover', \
 \
   'Florida': 'Tallahassee', \
 \
   'Georgia': 'Atlanta', 'Hawaii': 'Honolulu', \
 \
   'Idaho': 'Boise', \
 \
   'Illinois': 'Springfield', 'Indiana': 'Indianapolis', \
 \
   'Iowa': 'Des Moines', \
 \
   'Kansas': 'Topeka', 'Kentucky': 'Frankfort', \
 \
   'Louisiana': 'Baton Rouge', \
 \
   'Maine': 'Augusta', 'Maryland': 'Annapolis', \
 \
   'Massachusetts': 'Boston', \
 \
   'Michigan': 'Lansing', 'Minnesota': 'Saint Paul', \
 \
   'Mississippi': 'Jackson', \
 \
   'Missouri': 'Jefferson City', 'Montana': 'Helena', \
 \
   'Nebraska': 'Lincoln', \
 \
   'Nevada': 'Carson City', 'New Hampshire': 'Concord', \
 \
   'New Jersey': 'Trenton', \
 \
   'New Mexico': 'Santa Fe', 'New York': 'Albany', \
 \
   'North Carolina': 'Raleigh', \
 \
   'North Dakota': 'Bismarck', 'Ohio': 'Columbus', \
 \
   'Oklahoma': 'Oklahoma City', \
 \
   'Oregon': 'Salem', 'Pennsylvania': 'Harrisburg', \
 \
   'Rhode Island': 'Providence', \
 \
   'South Carolina': 'Columbia', \
 \
   'South Dakota': 'Pierre', 'Tennessee': 'Nashville', \
 \
   'Texas': 'Austin', 'Utah': 'Salt Lake City', \
 \
   'Vermont': 'Montpelier', \
 \
   'Virginia': 'Richmond', 'Washington': 'Olympia', \
 \
   'West Virginia': 'Charleston', \
 \
   'Wisconsin': 'Madison', 'Wyoming': 'Cheyenne'}

for k in capitals.keys():
state = input('Enter the capital of '+k+' :')
if state.upper() == capitals[k].upper():
right += 1
print('Correct')
else:
wrong += 1
print('Incorrect')
choice = input('Do you want to play again y/n: ')
if choice.upper() == 'N':
print('end of game')
else:
choice.upper() != 'Y'
print("invalid choice")

print('Number of correct answers is: ', right)
print("Number of incorrect answers is:", wrong)

main()



> On Jun 1, 2015, at 7:42 PM, Alan Gauld  wrote:
> 
> I've CCd the list. Please use reply all when responding to the list.
> Also please use plain text as HTML/RTF doesn't work on all
> systems and code in particular often gets mangled.
> 
> On 01/06/15 23:59, Stephanie Quiles wrote:
>> Hello again,
>> 
>> here is the final code… I think :) please see below. Is this is the easiest 
>> way to go about it? I appreciate your assistance!
>> 
>> defmain():
>> words = {}
>> count =0
> 
> Do you need count? What is its purpose?
>> withopen('words.txt')asdata:
>> forlineindata:
>> text = line.split()
>> forwordintext:
>> ifwordnot inwords:
>> words[word] =1
>> else:
>> words[word] +=1
> 
> Look into the setdefault() method of dictionaries.
> It can replace the if/else above.
> 
>> count +=1
>> print(words)
> 
> Aside from the two comments above, good job!
> 
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
> 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a dictionary for capital quiz program

2015-06-02 Thread Stephanie Quiles
Thank you all for your help! I have a text today but I am not confident with 
this. So basically, what I did wrong was the indentation? 

Thanks 

Stephanie Quiles
Sent from my iPhone

> On Jun 2, 2015, at 10:15 AM, Peter Otten <__pete...@web.de> wrote:
> 
> ZBUDNIEWEK. JAKUB wrote:
> 
>> I'm a newbie, but was able to tune it to correctly reply to user inputs.
> 
>> 2. Why (on Windows) do I have to give inputs in quotes not to cause an
>> error (for ll input the error is ' NameError: name 'll' is not defined')?
> 
> If you are running the script under Python 2 you should use
> raw_input() instead of input(). input() will take the user input and also 
> run eval() on it:
> 
> Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> input("? ")
> ? 1 + 1
> 2
>>>> raw_input("? ")
> ? 1 + 1
> '1 + 1'
> 
> Python 3 has no raw_input() and input() will behave like raw_input() in 
> Python 2.
> 
>> 1. My question is can it be optimized in any way?
> 
> In Python 2 capital.keys() builds a list. You can avoid that by iterating 
> over the dict directly:
> 
> for k in capitals:
>...
> 
> Not an optimization, but if the user enters neither Y nor N you might ask 
> again instead of assuming Y.
> 
> 
>> def main():
>> 
>>right = 0
>>wrong = 0
>>capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', "Arizona":
>>'Phoenix', \
>>   'Arkansas': 'Little Rock', 'California': 'Sacramento', \
>>   'Colorado': 'Denver', 'Connecticut': 'Hartford',
>>   'Delaware': 'Dover', \ 'Florida': 'Tallahassee', \
>>   'Georgia': 'Atlanta', 'Hawaii': 'Honolulu', \
>>   'Idaho': 'Boise',  \
>>   'Illinois': 'Springfield', 'Indiana': 'Indianapolis', \
>>   'Iowa': 'Des Moines', \
>>   'Kansas': 'Topeka', 'Kentucky': 'Frankfort', \
>>   'Louisiana': 'Baton Rouge', \
>>   'Maine': 'Augusta', 'Maryland': 'Annapolis', \
>>   'Massachusetts': 'Boston', \
>>   'Michigan': 'Lansing', 'Minnesota': 'Saint Paul', \
>>   'Mississippi': 'Jackson', \
>>   'Missouri': 'Jefferson City', 'Montana': 'Helena', \
>>   'Nebraska': 'Lincoln', \
>>   'Nevada': 'Carson City', 'New Hampshire': 'Concord', \
>>   'New Jersey': 'Trenton', \
>>   'New Mexico': 'Santa Fe', 'New York': 'Albany', \
>>   'North Carolina': 'Raleigh', \
>>   'North Dakota': 'Bismarck', 'Ohio': 'Columbus', \
>>   'Oklahoma': 'Oklahoma City', \
>>   'Oregon': 'Salem', 'Pennsylvania': 'Harrisburg', \
>>   'Rhode Island': 'Providence', \
>>   'South Carolina': 'Columbia', \
>>   'South Dakota': 'Pierre', 'Tennessee': 'Nashville', \
>>   'Texas': 'Austin', 'Utah': 'Salt Lake City', \
>>   'Vermont': 'Montpelier', \
>>   'Virginia': 'Richmond', 'Washington': 'Olympia', \
>>   'West Virginia': 'Charleston', \
>>   'Wisconsin': 'Madison', 'Wyoming': 'Cheyenne'}
>> 
>>for k in capitals.keys():
>>state = input('Enter the capital of '+k+' :')
>>if state.upper() == capitals[k].upper():
>>right += 1
>>print('Correct')
>>else:
>>wrong += 1
>>print('Incorrect')
>>choice = input('Do you want to play again y/n: ')
>>if choice.upper() == 'N':
>>print('end of game')
>>break
>>elif choice.upper() != 'Y':
>>print("invalid choice")
>> 
>>print('Number of correct answers is: ', right)
>>print("Number of incorrect answers is:", wrong)
>> 
>> main()
>> 
>> Regards,
>> Jakub
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a dictionary for capital quiz program

2015-06-02 Thread Stephanie Quiles
What is  the +k+ called? How exactly does it work? I'm a big confused on 
that... 

Stephanie Quiles
Sent from my iPhone

> On Jun 2, 2015, at 12:17 PM, Peter Otten <__pete...@web.de> wrote:
> 
> Alan Gauld wrote:
> 
>>> On 02/06/15 15:15, Peter Otten wrote:
>>> 
>>> Not an optimization, but if the user enters neither Y nor N you might ask
>>> again instead of assuming Y.
>> 
>> He does. He only breaks if the user enters N
>> 
>>>> choice = input('Do you want to play again y/n: ')
>>>> if choice.upper() == 'N':
>>>> print('end of game')
>>>> break
>>>> elif choice.upper() != 'Y':
>>>> print("invalid choice")
>> 
>> Y goes round again silently.
>> Anything other than Y or N prints the error then tries again.
> 
> ... with the next state. I meant that instead the question "Do you want to 
> play again y/n:" should be repeated until there is a valid answer, either y 
> or n.
> 
> Current behaviour:
> 
> $ python capitals.py 
> Enter the capital of Mississippi :Jackson
> Correct
> Do you want to play again y/n: x
> invalid choice
> Enter the capital of Oklahoma :
> ...
> 
> So "x" is a synonum for "n".
> 
> Suggested behaviour:
> 
> $ python capitals.py 
> Enter the capital of Mississippi :Jackson
> Correct
> Do you want to play again y/n: x
> invalid choice
> Do you want to play again y/n: z
> invalid choice
> Do you want to play again y/n: n
> end of game
> ...
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] create class Pet

2015-06-16 Thread Stephanie Quiles
Hello, Having trouble figuring out why this program is not running. could 
someone please take a look and see where I am going wrong? Here is the error 
message i am getting : 
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 
/Users/stephaniequiles/PycharmProjects/untitled3/pets.py
Traceback (most recent call last):
  File "/Users/stephaniequiles/PycharmProjects/untitled3/pets.py", line 2, in 

def main(get_name=name):
NameError: name 'name' is not defined

Process finished with exit code 1

Thanks  

Code is below:


# __author__ = 'stephaniequiles'

# write a class named Pet should include __name, __animal_type, __age

class Pet:
# pet class should have an __init__ method that creates these attributes.
def __init__(self, name, animal_type, age):
self.__name = 'name'
self.__animal_type = 'animal_type'
self.__age = 'age'

def set_name(self, name):
self.__name = 'name'

def set_type(self, animal_type):
self.__animal_type = animal_type

def set_age(self, age):
self.__age = age

def get_name(self):
return self.__name

def get_animal_type(self):
return self.__animal_type

def get_age(self):
return self.__age

# create methods,  set_name , set_animal_type, set_age,  get_name, 
get_animal_type
# get_age

# write a program that creates an object of the class and prompts the use to 
enter
# name, type, age of their pet.

# data should be stored as objects attributes.
# use objects accessor methods to retrieve the pet's name, type and age
# display data on screen

# __author__ = 'stephaniequiles'
def main():
name = input('what is the name of the pet?: ')
animal_type = ('Please enter a type of pet: ')
age = int(input('Enter age of pet: '))
self.get_name(name, animal_type, age)
print('This will be saved to file.')
print('Here is a the data you entered: ')
print('Pet Name: ', pet.get_name)
print('Animal Type:', pet.get_animal_type)
print('Age: ', pet.get_age)


main()






___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] create class Pet

2015-06-16 Thread Stephanie Quiles
> sorry this is the correct error. it allows me to enter name and age but then 
> i get the message: 

/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 
/Users/stephaniequiles/PycharmProjects/untitled3/pets.py
what is the name of the pet?: riley
Please enter a type of pet: cat
Enter age of pet: 11
Traceback (most recent call last):
  File "/Users/stephaniequiles/PycharmProjects/untitled3/pets.py", line 15, in 

main()
  File "/Users/stephaniequiles/PycharmProjects/untitled3/pets.py", line 7, in 
main
pet.get_name(name, animal_type, age)
AttributeError: 'module' object has no attribute 'get_name'

Process finished with exit code 1

class Pet:
# pet class should have an __init__ method that creates these attributes.
def __init__(self, name, animal_type, age):
self.__name = "name"
self.__animal_type = "animal_type"
self.__age = "age"

def set_name(self, name):
self.__name = "name"

def set_type(self, animal_type):
self.__animal_type = animal_type

def set_age(self, age):
self.__age = age

def get_name(self):
return self.__name

def get_animal_type(self):
return self.__animal_type

def get_age(self):
return self.__age

# create methods,  set_name , set_animal_type, set_age,  get_name, 
get_animal_type
# get_age

# write a program that creates an object of the class and prompts the use to 
enter
# name, type, age of their pet.

# data should be stored as objects attributes.
# use objects accessor methods to retrieve the pet's name, type and age
# display data on screen

# __author__ = 'stephaniequiles'
import pet
def main():
name = input("what is the name of the pet?: ")
animal_type = input("Please enter a type of pet: ")
age = input("Enter age of pet: ")
pet.get_name(name, animal_type, age)
print("This will be saved to file.")
print("Here is a the data you entered: ")
print("Pet Name: ", pet.get_name)
print("Animal Type:", pet.get_animal_type)
print("Age: ", pet.get_age)


main()



> On Jun 16, 2015, at 3:49 PM, Mark Lawrence  wrote:
> 
> On 16/06/2015 17:45, Stephanie Quiles wrote:
>> Hello, Having trouble figuring out why this program is not running. could 
>> someone please take a look and see where I am going wrong? Here is the error 
>> message i am getting : 
>> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 
>> /Users/stephaniequiles/PycharmProjects/untitled3/pets.py
>> Traceback (most recent call last):
>>   File "/Users/stephaniequiles/PycharmProjects/untitled3/pets.py", line 2, 
>> in 
>> def main(get_name=name):
>> NameError: name 'name' is not defined
>> 
>> Process finished with exit code 1
>> 
>> Thanks 
>> 
>> Code is below:
>> 
>> 
>> # __author__ = 'stephaniequiles'
>> 
>> # write a class named Pet should include __name, __animal_type, __age
>> 
>> class Pet:
>> # pet class should have an __init__ method that creates these attributes.
>> def __init__(self, name, animal_type, age):
>> self.__name = 'name'
>> self.__animal_type = 'animal_type'
>> self.__age = 'age'
>> 
>> def set_name(self, name):
>> self.__name = 'name'
> 
> Further to Alan's answer the above methods are wrong.  You're setting all the 
> instance variables to strings instead of the actual variable names.  Get rid 
> of the single quotes.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] create class Pet

2015-06-17 Thread Stephanie Quiles
You are right I don't understand functions very well still. This prompts the 
next question is there a book or online resource that you suggest I look at? 
Right now I am using a text book provides by the instructor called Starting Out 
With Python 3rd ed.  
Anything you can suggest I reference would be appreciated. I will review the 
code when I get home. 

Thanks 
Stephanie Quiles
Sent from my iPhone

> On Jun 17, 2015, at 3:40 AM, Alan Gauld  wrote:
> 
> On 16/06/15 21:15, Stephanie Quiles wrote:
>>> sorry this is the correct error.
> 
> 
>>   File "/Users/stephaniequiles/PycharmProjects/untitled3/pets.py", line 7, 
>> in main
>> pet.get_name(name, animal_type, age)
>> AttributeError: 'module' object has no attribute 'get_name'
> 
> There are several errors in this line, all of which suggest
> you don't really understand what you are doing with functions, #
> classes and objects. You need to re-read your tutorial material
> more closely.
> 
> 1) Starting with the reported error.
> You called
> 
> pet.get_name(...)
> 
> pet is the name of your file so Python sees that as a module.
> But get_name is a method of your Pet class. The class name is
> captalized and case matters in Python. 'Pet' is not the
> same as 'pet' That's why it says there is no such module
> attribute as get_name.
> 
> 2) The method call has 3 arguments: name, type and age.
> But your method definition has no attributes (apart
> from the obligatory self). When you call a function
> (or method) you must only include the arguments that
> the function definition expects. So your call to
> get_name() would have failed even if you had not
> misspelled pet.
> 
> 3) get_name() returns a string value - the __name of the pet.
> You call get_name() but do not use or store the result so
> it is thrown away. I suspect you meant to print the result
> so you should have written something like:
> print ( my_pet.getname() )
> 
> 4) get_name() is a method of the class Pet. That means
> you should call it as an attribute of an object which
> is an instance of Pet. That is, you must create an
> instance of Pet before you try to use any of its methods.
> You did not create any instances. Interestingly, your
> __init__() method does take the 3 parameters that
> you tried to pass to get_name(). This means that
> you could have replaced the get_name() call with
> 
> my_pet = Pet(name, animal_type, age)
> 
> Now that we have dealt with that line lets move on
> to the rest of your main function...
> 
> You have several lines like:
> 
> print("Pet Name: ", pet.get_name)
> 
> The problem here is that you are passing the method name
> into the print function. You are not *calling* the method.
> Also you are using the module name (pet) to access get_name,
> but it needs to be an instance of Pet - see above.
> 
> To do all that you must use abn instance and put parentheses
> after the method name, so it should look like:
> 
> print("Pet Name: ", my_pet.get_name() )
> 
> The final set of errors have already been highlighted by Mark.
> Namely where you set attribute values in the class methods
> you are creating strings instead of using the variables.
> ie you are writing
> 
>  def set_name(self, name):
>  self.__name = "name"
> 
> where it should be
> 
> def set_name(self, name):
> self.__name = name
> 
> with no quote signs.
> 
> If you make all those changes I think it should work.
> However, given the number and nature of the errors, I cannot
> help but think you need to go back and re-read your
> tutorial material. Details are very important in programming
> and you seem to still be confused about naming, function definitions and 
> calling and the relationship between classes and objects/instances.
> 
>> 
>> Process finished with exit code 1
>> 
>> class Pet:
>> # pet class should have an __init__ method that creates these attributes.
>> def __init__(self, name, animal_type, age):
>> self.__name = "name"
>> self.__animal_type = "animal_type"
>> self.__age = "age"
>> 
>> def set_name(self, name):
>> self.__name = "name"
>> 
>> def set_type(self, animal_type):
>> self.__animal_type = animal_type
>> 
>> def set_age(self, age):
>> self.__age = age
>> 
>> def get_name(self):
>> return self.__name
>> 
>> def get_animal_type(self):
>> return self.__animal_type

[Tutor] GUI program

2015-06-30 Thread Stephanie Quiles
Hello, i am attempting to create a GUI program using Python 3.4. please see the 
pasted code below. Why is nothing showing up? i am using Pycharm to run the 
program to see what it does and it says there are no errors but it does not 
show me an output. please let me know where i am falling short on this. 

Thank you 

__author__ = 'stephaniequiles'

""" Write a GUI program that displays your name and address when a button is 
clicked. when the user clicks the 'show info' button, the
program should display your name and address, as shown in the sketch."""

import tkinter


class AddressGUI:
def __init__(self):
self.main_window = tkinter.Tk()

self.top_frame= tkinter.Frame()
self.mid_frame= tkinter.Frame()
self.bottom_frame = tkinter.Frame()

self.name_label= tkinter.Label(self.top_frame,\
 text='Steven Marcus')

self.name_label.pack(side='left')


self.value = tkinter.StringVar()
self.address_label = tkinter.Label(self.mid_frame,\
   text='274 Baily Drive Waynesville, 
NC 27999')

self.address_label.pack(side='left')

self.show_button = tkinter.Button(self.bottom_frame,\
  text="show info",\
  command=self.showinfo)
self.quit_button = tkinter.Button(self.bottom_frame,\
  tect ='Quit',\
  command=self.main_window.destroy)

self.show_button.pack(side='left')
self.quit_button.pack(side='left')

self.top_frame.pack()
self.mid_frame.pack()
self.bottom_frame.pack()

tkinter.mainloop()

def showinfo(self):
name = 'Steven Marcus'
address = '274 Baily Drive Waynesville, NC 27999'
info = name + address

allinfo = AddressGUI()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor