[Tutor] Help with Multiple Inheritance in Classes

2017-02-07 Thread Vusa Moyo
I have a suspicion my lecturer's question is flawed, so I'd like to pose it
to you guys to confirm my suspicions.

Here goes..

I've gone and created a Class Cat1(cat): <-- inherited class, but cant seem
get the code right which allows the test code to run successfully.

We have a class defined for cats. Create a new cat called cat1. Set cat1 to
be a grey Burmese cat worth 3000 with the name Whiskers.

 # define the Cat class

 class Cat:
 name = ""

 kind = "cat"
 color = ""
 value = 100.00
 def description(self):

desc_str = "%s is a %s %s cat worth R%.2f." % (self.name, self.color,
self.kind, self.value)

 return desc_str

# your code goes here


# test code

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


Re: [Tutor] (no subject)

2017-02-07 Thread David Rock
> On Feb 7, 2017, at 15:09, တာန္ခတ္သန္  wrote:
> 
> 
> # RockPaperScissors
> 
> import random
> print ("Hello.. Welcome from Rock, Paper, Scissors Game!!\n"
>   +"Game instruction:\n"
>   +"You will be playing with the computer.\n"
>   +"You need to choose one of your choice: Rock, Paper or Scissors.\n"
>   +"Enter 'e' to exit the game.\n")
> 
> game_command = {"r":"Rock","p":"Paper","s":"Scissors","e":"Exit"}
> 
> 
> score = 0
> player = 0
> try:
>while player == 'r' and player == 'p' and player == 's':
> 

There are two major things that you need to address first.

1. You never ask for user input before starting your while loop
2. Your while loop is testing for r, p, and s to all be equal to each other and 
set, which is not what you want to test.

Basically, your while loop is immediately false as soon as you run your script. 
 You need to rework your logic to test the player’s value.


— 
David Rock
da...@graniteweb.com




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


[Tutor] (no subject)

2017-02-07 Thread တာန္ခတ္သန္
Hi,


I am just start learning Python and I have an activity to do
RockPaperScissors game using dictionary. I have written my code and it
doesn't work at all. I am sending my code and the
requirements. Can you please have a look and point out what is wrong there.
Thank you very much.

Warm regards,
Pau

program requirements:

 The program will display an appropriate welcome message and user
instructions.

 The program must use a Python dictionary to hold data shown in the table
below:

Game Command  Value

R Rock

P Paper

S  Scissors

E  Exit

 The player will enter their choice of shape by entering a valid Game
Command.

 Any invalid input must generate an exception that is handled and used to
display an appropriate error message.

 For correct inputs, the computer will randomly pick a dictionary item
(other than ‘Exit’) and compare that value with the user’s, before
returning the game result.

 For the game result the program must return details of the following:

o The user’s selection

o The computer’s selection

o The winning hand

o A running total of user wins including this game and previous games

 The program will repeat the game until the user exits by entering ‘e’.

# RockPaperScissors

import random
print ("Hello.. Welcome from Rock, Paper, Scissors Game!!\n"
   +"Game instruction:\n"
   +"You will be playing with the computer.\n"
   +"You need to choose one of your choice: Rock, Paper or Scissors.\n"
   +"Enter 'e' to exit the game.\n")

game_command = {"r":"Rock","p":"Paper","s":"Scissors","e":"Exit"}


score = 0
player = 0
try:
while player == 'r' and player == 'p' and player == 's':


pc = random.choice( list(game_command.keys())[:3])
player = input("\nPlease enter your choice:'r','p' or 's': ")
print ("You selects: ", player)
print ("PC selects:",pc)


if player == pc:
print("It's a Tie!")
score = score
print("Your score is: ",score)

elif player == "r":
if pc == "p":
print("PC win!")
else:
print("You win!")
score = score + 1
print("Your score is: ",score)

elif player == "p":
if pc == "s":
print("PC win!")
else:
print("You win!")
score = score + 1
print("Your score is: ",score)

elif player == "s":
if pc == "r":
print("PC win!")
else:
print("You win!")
score = score + 1
print("Your score is: ",score)
elif player == 'e' :
break
print("You exit the game.")
except ValueError:
print("\nInvalid character,try again!")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiple tabs using tkinter

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 19:51, Zachary Ware wrote:

>> But Tix has over 40 extra widgets including a tabbed notepad,
>> balloon, meter, shell and and a very powerful (but undocumented!)
>> grid control.
> 
> Very little of tkinter is actually documented outside of the official
> Tcl/Tk docs, unfortunately.  

Tix is barely documented even there!
I was actually considering writing a book to document the Tix
toolkit. If its now deprecated I won't bother!! :-)

> How does tix.Grid differ from the
> standard grid geometry manager (.grid() method on widgets)?

It's a widget not a window manager (although Tix does provide
a new "Form" WM, but I've never used it). The grid is a table
or simple spreadsheet control. Most GUI toolkits have one
but Tkinter doesn't... yet...

>> The most important and commonly used seem to have been
>> incorporated into the latest ttk, but not all of them.
> 
> Which ones are missing?  I'd recommend raising issues against Tk for
> having them added.

I'll need to do a bit of dir() and diff() to answer that

> There's some Tcl, but mostly C; see

Yes, I discovered that once I started doing some deeper
digging... see my other post that seems to have crossed
paths with yours.


-- 
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] Multiple tabs using tkinter

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 18:59, Alan Gauld via Tutor wrote:

> It should be easy since its just native Tcl code, there's no C

Scratch that, I just found a C API for Tix so I guess it
has some C after all.


-- 
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] Tkinter Calendar to receive user entry.

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 19:40, Peter Otten wrote:

>>> from ttkcalendar import Calendar
>>
>> Doesn't work for me in either Python 3.6.0 or in Python 2.7.6
>>
>> Which version of 2.7 are you using?
> 
> The distribution's Python 2.7.6 on Linux Mint 17. After fixing the import 
> statements...

OK, I went back to your original post again and realized I
needed to download the ttkcalendar.py, its not a standard
module...

works now.

-- 
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] Multiple tabs using tkinter

2017-02-07 Thread Zachary Ware
On Tue, Feb 7, 2017 at 12:59 PM, Alan Gauld via Tutor  wrote:
> On 07/02/17 16:41, Zachary Ware wrote:
>
>> Full disclosure, I've never actually used Tix beyond making it build
>> with the rest of CPython on Windows and making sure it actually worked
>> on one of my Linux buildbot workers.  I have only ever seen it as a
>> maintenance headache :)
>
> The beauty of Tix is that it is a full superset of Tkinter
> so you can just put this at the top and it converts your
> code to use Tix:
>
> replace
>
> import Tkinter
>
> with
>
> import Tix as Tkinter

That's just because tix.py does "from tkinter import *".  You can
achieve the same by doing 'from tkinter import *;from tkinter.ttk
import *' (in a separate 'tk.py' if you want everything namespaced in
your code).

> But Tix has over 40 extra widgets including a tabbed notepad,
> balloon, meter, shell and and a very powerful (but undocumented!)
> grid control.

Very little of tkinter is actually documented outside of the official
Tcl/Tk docs, unfortunately.  How does tix.Grid differ from the
standard grid geometry manager (.grid() method on widgets)?

> The most important and commonly used seem to have been
> incorporated into the latest ttk, but not all of them.

Which ones are missing?  I'd recommend raising issues against Tk for
having them added.

>> "Less available" rather than "unavailable" :).  Tix ships with Tcl/Tk
>> with CPython on Windows; on Linux, you'd need to install it separately
>> from Tcl/Tk and python/tkinter.  I honestly don't have a clue how
>> you'd get it on macOS or any other platform that doesn't provide it in
>> a system repository.
>
> It should be easy since its just native Tcl code, there's no C
> involved so far as I know (I haven't checked!). So anywhere Tcl
> runs Tix should work.

There's some Tcl, but mostly C; see
http://svn.python.org/view/external/tix-8.4.3.x/ (particularly the
'generic', 'unix', and 'win' directories).

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


Re: [Tutor] Error when trying to use classes

2017-02-07 Thread George Fischhof
2017-02-07 16:34 GMT+01:00 Rafael Skovron :

> I'm trying to learn how to use Classes but I keep getting  NameErrors no
> matter what code I put into the script.
>
> Any ideas why?
>
> My general workflow is I edit in vim, then invoke python3 interpreter,
> import the module and try to use the Class and methods from the class.
>
> For example, importing customer.py and assigning this object yields:
>
> >>> rafael = Customer('rafael',100.0)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'Customer' is not defined
>
>
>
> class Customer(object):
> """A customer of ABC Bank with a checking account. Customers have
> thefollowing properties:
> Attributes:name: A string representing the customer's
> name.balance: A float tracking the current balance of the
> customer's account."""
>
> def __init__(self, name, balance=0.0):
> """Return a Customer object whose name is *name* and starting
>   balance is *balance*."""
> self.name = name
> self.balance = balance
>
> def withdraw(self, amount):
> """Return the balance remaining after withdrawing *amount*
>dollars."""
> if amount > self.balance:
> raise RuntimeError('Amount greater than available balance.')
> self.balance -= amount
> return self.balance
>
> def deposit(self, amount):
> """Return the balance remaining after depositing *amount*
>   dollars."""
> self.balance += amount
> return self.balance
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


Hi,

with this statement:
>>> rafael = Customer('rafael',100.0)
you (the program) creates an instance of Customer class

to import the class (this is the first), you should use the import
statement:
>>> from customer import Customer
after this the program will work.

BR,
George

PS.: pycharm from JetBrains is a very good python ide. ... (instead of vim
;-) )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter Calendar to receive user entry.

2017-02-07 Thread Peter Otten
Alan Gauld via Tutor wrote:

> On 07/02/17 10:18, Peter Otten wrote:
> 
>> $ cat demo.py
>> #!/usr/bin/env python
>> import calendar
>> import ttk
>> import Tkinter
>> from ttkcalendar import Calendar
> 
> Doesn't work for me in either Python 3.6.0 or in Python 2.7.6
> 
> Which version of 2.7 are you using?

The distribution's Python 2.7.6 on Linux Mint 17. After fixing the import 
statements...

$ head ttkcalendar.py
"""
Simple calendar using ttk Treeview together with calendar and datetime
classes.
"""
import calendar

try:
import Tkinter
import tkFont
import ttk
except ImportError: # py3k
import tkinter as Tkinter
import tkinter.font as tkFont
from tkinter import ttk

def get_calendar(locale, fwday):
# instantiate proper calendar class
if locale is None:
return calendar.TextCalendar(fwday)
else:
$ cat demo.py
#!/usr/bin/env python
import calendar

try:
import tkinter as tk
from tkinter import ttk
except ImportError:
import ttk
import Tkinter as tk

from ttkcalendar import Calendar

def test2():
import sys
root = tk.Tk()
root.title('Ttk Calendar')
ttkcal = Calendar(firstweekday=calendar.SUNDAY)
ttkcal.pack(expand=1, fill='both')

if 'win' not in sys.platform:
style = ttk.Style()
style.theme_use('clam')

root.mainloop()

x = ttkcal.selection
print('x is: {}'.format(x))

test2()

... Python 3.4.3 works, too, as does the most recent compiled-from-source 
version I have lying around,

$ python3.7
Python 3.7.0a0 (default:09d4d47ad210, Jan 31 2017, 22:08:14) 
[GCC 4.8.4] on linux

The underlying tcl is 8.6.

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


Re: [Tutor] Error when trying to use classes

2017-02-07 Thread Alex Kleider

On 2017-02-07 07:34, Rafael Skovron wrote:
I'm trying to learn how to use Classes but I keep getting  NameErrors 
no

matter what code I put into the script.

Any ideas why?


Assuming the code you've edited using vim is in a file mymodule.py
And after invoking the interpreter you issue the following:

import mymodule.py

your instantiation statement needs to be

rafael = mymodule.Customer('rafael', 100.0)


Alternatively you can use the following import statement (not generally 
recommended:)

from mymodule import Customer





My general workflow is I edit in vim, then invoke python3 interpreter,
import the module and try to use the Class and methods from the class.

For example, importing customer.py and assigning this object yields:


rafael = Customer('rafael',100.0)

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'Customer' is not defined



class Customer(object):
"""A customer of ABC Bank with a checking account. Customers have
thefollowing properties:
Attributes:name: A string representing the customer's
name.balance: A float tracking the current balance of the
customer's account."""

def __init__(self, name, balance=0.0):
"""Return a Customer object whose name is *name* and starting
  balance is *balance*."""
self.name = name
self.balance = balance

def withdraw(self, amount):
"""Return the balance remaining after withdrawing *amount*
   dollars."""
if amount > self.balance:
raise RuntimeError('Amount greater than available 
balance.')

self.balance -= amount
return self.balance

def deposit(self, amount):
"""Return the balance remaining after depositing *amount*
  dollars."""
self.balance += amount
return self.balance
___
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] Tkinter Calendar to receive user entry.

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 10:18, Peter Otten wrote:

> $ cat demo.py
> #!/usr/bin/env python
> import calendar
> import ttk
> import Tkinter
> from ttkcalendar import Calendar

Doesn't work for me in either Python 3.6.0 or in Python 2.7.6

Which version of 2.7 are you using?

-- 
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] Error when trying to use classes

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 15:34, Rafael Skovron wrote:

> My general workflow is I edit in vim, then invoke python3 interpreter,
> import the module and try to use the Class and methods from the class.
> 
> For example, importing customer.py and assigning this object yields:
> 
 rafael = Customer('rafael',100.0)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'Customer' is not defined

You didn't show us the import but I'm guessing
you just did

import customer

In that case you need to reference the module:

rafael = customer.Customer()

HTH
-- 
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] Multiple tabs using tkinter

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 16:41, Zachary Ware wrote:

> Full disclosure, I've never actually used Tix beyond making it build
> with the rest of CPython on Windows and making sure it actually worked
> on one of my Linux buildbot workers.  I have only ever seen it as a
> maintenance headache :)

The beauty of Tix is that it is a full superset of Tkinter
so you can just put this at the top and it converts your
code to use Tix:

replace

import Tkinter

with

import Tix as Tkinter

But Tix has over 40 extra widgets including a tabbed notepad,
balloon, meter, shell and and a very powerful (but undocumented!)
grid control.

The most important and commonly used seem to have been
incorporated into the latest ttk, but not all of them.

> "Less available" rather than "unavailable" :).  Tix ships with Tcl/Tk
> with CPython on Windows; on Linux, you'd need to install it separately
> from Tcl/Tk and python/tkinter.  I honestly don't have a clue how
> you'd get it on macOS or any other platform that doesn't provide it in
> a system repository.

It should be easy since its just native Tcl code, there's no C
involved so far as I know (I haven't checked!). So anywhere Tcl
runs Tix should work.

-- 
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] Tkinter Calendar to receive user entry.

2017-02-07 Thread Pooja Bhalode
Hi Alan,

Thank you so much for your advice, I would start looking into learning some
object oriented programming to make myself familiar with it. That would
help me move ahead as well.

Hi Peter,

Thank you so much for your reply. Yes, that was the example that I was
looking at on stackoverflow. Yes, it works for me as well now. Thanks a lot
for your help there.

Yours truly,
Pooja

On Tue, Feb 7, 2017 at 5:18 AM, Peter Otten <__pete...@web.de> wrote:

> Alan Gauld via Tutor wrote:
>
> > On 07/02/17 00:24, Pooja Bhalode wrote:
> >
> >> I am trying to create a calendar using tkinter GUI such that when the
> >> user opens the GUI,
> >
> > So far as I'm aware there is no such Calendar widget in the standard
> > modules, you would need to find a third party module.
> >
> >> Can some one please help me with this? I looked up on the website, I
> came
> >> across this one,
> >> http://stackoverflow.com/questions/27774089/
> >> python-calendar-widget-return-the-user-selected-date
> >> But when I try to run it, it gives me an error saying that it is not
> able
> >> to recognize Calendar.
> >
> > I'm really puzzled by that post because there is non Calendar widget
> > in ttk (or Tix) as of Python 3.4. They are discussing code that
> > should not work but they seem to have it working. I assume there
> > is a non standard ttk module out there somewhere?
>
> The question on stackoverflow points to
>
> http://svn.python.org/projects/sandbox/trunk/ttk-
> gsoc/samples/ttkcalendar.py
>
> A few imports are sufficient to turn test2() from the answer into a working
> script (python 2):
>
> $ cat demo.py
> #!/usr/bin/env python
> import calendar
> import ttk
> import Tkinter
> from ttkcalendar import Calendar
>
> def test2():
> import sys
> root = Tkinter.Tk()
> root.title('Ttk Calendar')
> ttkcal = Calendar(firstweekday=calendar.SUNDAY)
> ttkcal.pack(expand=1, fill='both')
>
> if 'win' not in sys.platform:
> style = ttk.Style()
> style.theme_use('clam')
>
> root.mainloop()
>
> x = ttkcal.selection
> print 'x is: ', x
>
> test2()
> $ ./demo.py
> x is:  2017-05-11 00:00:00
>
>
> ___
> 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] Multiple tabs using tkinter

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 03:56, Pooja Bhalode wrote:

> you mentioned that there are multiple toolkits which can be used instead of
> tkinter. I was also looking into wxpython for building a explorer bar.
> Mainly, I have to build a software entirely using python and thus, needed
> all these things put in place. I have been exploring things on how to do
> small bits of these using Tkinter. Would you suggest me to use some other
> toolkit instead of tkinter or maybe combine and use whichever whenever
> needed?

You can do it all in Tkinter if you want, it just takes more work. You
will need to create your own widgets. Other toolkits (like wxPython)
come with more powerful widgets already built, but the trade off is that
they are
1) not part of standard python which means you (and your users)
   need to install them
2) They are usually more difficult(*) to use than Tkinter
   (and will require more OOP knowlege than you currently have)

(*)But thats a relative thing, they are not very
difficult, just different. And once you get into them they
are much easier to use than creating your own widgets!
But there are no perfect toolkits, you need to look at
each and judge which one is best for you.

There is a page here that lists most of the options:

https://wiki.python.org/moin/GuiProgramming

-- 
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] Tkinter Calendar to receive user entry.

2017-02-07 Thread Peter Otten
Alan Gauld via Tutor wrote:

> On 07/02/17 00:24, Pooja Bhalode wrote:
> 
>> I am trying to create a calendar using tkinter GUI such that when the
>> user opens the GUI,
> 
> So far as I'm aware there is no such Calendar widget in the standard
> modules, you would need to find a third party module.
> 
>> Can some one please help me with this? I looked up on the website, I came
>> across this one,
>> http://stackoverflow.com/questions/27774089/
>> python-calendar-widget-return-the-user-selected-date
>> But when I try to run it, it gives me an error saying that it is not able
>> to recognize Calendar.
> 
> I'm really puzzled by that post because there is non Calendar widget
> in ttk (or Tix) as of Python 3.4. They are discussing code that
> should not work but they seem to have it working. I assume there
> is a non standard ttk module out there somewhere?

The question on stackoverflow points to

http://svn.python.org/projects/sandbox/trunk/ttk-gsoc/samples/ttkcalendar.py

A few imports are sufficient to turn test2() from the answer into a working 
script (python 2):

$ cat demo.py
#!/usr/bin/env python
import calendar
import ttk
import Tkinter
from ttkcalendar import Calendar

def test2():
import sys
root = Tkinter.Tk()
root.title('Ttk Calendar')
ttkcal = Calendar(firstweekday=calendar.SUNDAY)
ttkcal.pack(expand=1, fill='both')

if 'win' not in sys.platform:
style = ttk.Style()
style.theme_use('clam')

root.mainloop()

x = ttkcal.selection
print 'x is: ', x

test2()
$ ./demo.py 
x is:  2017-05-11 00:00:00


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


Re: [Tutor] Help with this work

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 04:08, Sasiliyu Adetunji wrote:
> I have been working on yhis assignment

You are asking for help but in what regard?
There is no question or problem statement in your post?

I've put some general comments below...

> class ShoppingCart(object):
> 
>   def __init__(self):
> self.total = 0
> self.items = {}
> 
>   def add_item(self, item_name, quantity, price):
> if not item_name in self.items:
>   self.items[item_name] = quantity
> else:
>   self.items[item_name] += quantity

This is often better done using the get()
or setdefault() methods of the dictionary.
For example:

self.items[item_name] = self.items.get(item_name,0)) + quantity

> self.total += quantity * price
> 
>   def remove_item(self, item_name, quantity, price):
> if quantity > self.items[item_name]:
>   self.items[item_name] = quantity
> else:
>   self.items[item_name] -= quantity
> self.total -= quantity * price

I'm pretty sure the first part of the if statement is wrong.
Read the specification again.

Also there is a more subtle problem with your last line
if quantity is greater than the stored self.items count.
Try working through it manually with some before/after
figures and see if the results are what you would expect.

>   def checkout(self, cash_paid):
> self.cash_paid = cash_paid
> if cash_paid < self.total:
>   return "Cash paid not enough"
> else:
>   return cash_paid - self.total

This meets the specification but I hate the design
here. But that's not your fault

> class Shop(ShoppingCart):
>   def __init__(self):
> self.quantity = 100
> 
>   def remove_item(self):
> self.quantity -= 1
> 

It says override the remove_item.
But shopping carts remove_item takes 3 parameters
so your new version should take the same three
parameters. It should probably call the superclass's
remove_item too. However I agree that you have done
what the spec asked for, I just suspect the spec
is badly written for this particular case...

> Kindly assist me

In what way? You haven't said what the issue is.


-- 
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] Multiple tabs using tkinter

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 03:31, Zachary Ware wrote:

> ttk rather than Tix; Tix is unmaintained and soft-deprecated in 3.6+.

Really? Thats a pity.
Tix was supposed to be the module with the extra widgets
and ttk was purely the themed versions of same. Its a shame
to confuse their purposes.

OTOH it does mean that the full range of widgets should
hopefully appear in ttk. Does that also mean that ttk
is now a full superset of Tkinter like Tix? (ttk used
to be a subset so you had to import both...)

> Tk, and also looks significantly more native than classic Tk or Tix.

Sure that was its original purpose.

> Tix is also less available on platforms other than Windows, 

Really? I've used it on Windows and Linux.
Where is it missing? - MacOS?

You may finally have just given me a motivation to move to
Python 3.6 from 3.4... :-)

-- 
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] Help Please on python

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 02:12, Laura Garcia wrote:
> I need to create a python code that  should simulate throwing darts by
> random landing between (a random x and a random y)0 and 1.  and the program
> should print out number of darts that land within a rectangle.

Look in the random module. There are a bunch of different
random number generating functions in thee, just choose
the one that looks best suited to your task.

For the rest its just a case of some basic math. Write
some code and if you get stuck come back with a specific
question and we can try to answer it.


-- 
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] Tkinter Calendar to receive user entry.

2017-02-07 Thread Alan Gauld via Tutor
On 07/02/17 00:24, Pooja Bhalode wrote:

> I am trying to create a calendar using tkinter GUI such that when the user
> opens the GUI, 

So far as I'm aware there is no such Calendar widget in the standard
modules, you would need to find a third party module.

> Can some one please help me with this? I looked up on the website, I came
> across this one,
> http://stackoverflow.com/questions/27774089/python-calendar-widget-return-the-user-selected-date
> But when I try to run it, it gives me an error saying that it is not able
> to recognize Calendar.

I'm really puzzled by that post because there is non Calendar widget
in ttk (or Tix) as of Python 3.4. They are discussing code that
should not work but they seem to have it working. I assume there
is a non standard ttk module out there somewhere?

> I would really appreciate some help with this. I also came to know that I
> could use calendar.Calendar to create an object for the same, but I am not
> good with working with objects 

You probably need to spend some time on that first. Everything
in Python is an object (even strings and numbers and lists etc).
So you really need to get comfortable with the idea of
accessing attributes and methods of objects.

You don't need to worry about creating classes and so on(yet),
but you do need to understand how to use other peoples objects.

Finally, if you are going to ask questions about code its
always good to show us exactly what code you typed as well
as the full error message.

-- 
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] Multiple tabs using tkinter

2017-02-07 Thread Pooja Bhalode
Hi Alan and Zackary,

Thank you so much for your inputs. I really appreciate any help on these
things.

Alan,

you mentioned that there are multiple toolkits which can be used instead of
tkinter. I was also looking into wxpython for building a explorer bar.
Mainly, I have to build a software entirely using python and thus, needed
all these things put in place. I have been exploring things on how to do
small bits of these using Tkinter. Would you suggest me to use some other
toolkit instead of tkinter or maybe combine and use whichever whenever
needed?

I was just going through your website and looking at the tutorials, wanted
to thank you. I think those would be really really helpful.

Zackary,

I tried using ttk for the multiple tabs feature and that worked out really
nicely.
Thank you once again.
I would also look into the ttk.Combobox package. Thank you

Yours truly,
Pooja


On Mon, Feb 6, 2017 at 10:31 PM, Zachary Ware 
wrote:

> On Mon, Feb 6, 2017 at 7:31 PM, Alan Gauld via Tutor 
> wrote:
> > On 06/02/17 16:40, Pooja Bhalode wrote:
> >
> >> I was wondering if someone could help me regarding multiple tabs in
> >> tkinter.
> >
> > Look at the tabbed notebook in the Tix module.
> > It should do what you want.
>
> ttk rather than Tix; Tix is unmaintained and soft-deprecated in 3.6+.
> ttk provides most of the useful parts of Tix, is maintained as part of
> Tk, and also looks significantly more native than classic Tk or Tix.
> Tix is also less available on platforms other than Windows, whereas
> ttk is present in any Tk 8.5 or greater.
>
> > I give a tutorial on its use in my recent book but you can
> > also find online tutorials, especially in Tcl (Python ones
> > are much harder to find)
> >
> >> Also, I was wondering if there is a way in tkinter to create an explorer
> >> bar that we see in finder in OS Mac or windows. I found a way to do that
> >> using wxpython, but was wondering if there is a way using tkinter.
> >
> > Tkinter is a relatively low level GUI toolkit. You can
> > build most things but you have to start with the basic
> > widgets. So an explorer bar is just an Entry widget to
> > which you can attach any functionality you care to create.
>
> Also have a look at ttk.Combobox, which combines an Entry and Listbox
> (and, I think, if the list is long enough, a Scrollbar) into a
> drop-down menu widget.
>
> --
> Zach
> ___
> 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] Help with this work

2017-02-07 Thread Sasiliyu Adetunji
Hi,
I have been working on yhis assignment

Create a class called ShoppingCart

Create a constructor that takes no arguments and sets the total attribute
to zero, and initializes an empty dict attribute named items.

Create a method add_item that requires item_name, quantity and price arguments.
This method should add the cost of the added items to the current value of
total. It should also add an entry to the items dict such that the key is
the item_name and the value is the quantity of the item.

Create a method remove_item that requires similar arguments as add_item. It
should remove items that have been added to the shopping cart and are not
required. This method should deduct the cost of the removed items from the
current total and also update the items dict accordingly.

If the quantity of an item to be removed exceeds the current quantity of
that item in the cart, assume that all entries of that item are to be
removed.

Create a method checkout that takes in cash_paid and returns the value of
balance from the payment. If cash_paid is not enough to cover the total,
return "Cash paid not enough".

Create a class called Shop that has a constructor which takes no arguments
and initializes an attribute called quantity at 100.

Make sure Shop inherits from ShoppingCart.

In the Shop class, override the remove_item method, such that calling
Shop's remove_item with no arguments decrements quantity by one.


For now this is what i have

class ShoppingCart(object):

  def __init__(self):

self.total = 0

self.items = {}

  def add_item(self, item_name, quantity, price):

if not item_name in self.items:

  self.items[item_name] = quantity

else:

  self.items[item_name] += quantity

self.total += quantity * price

  def remove_item(self, item_name, quantity, price):

if quantity > self.items[item_name]:

  self.items[item_name] = quantity

else:

  self.items[item_name] -= quantity

self.total -= quantity * price

  def checkout(self, cash_paid):

self.cash_paid = cash_paid

if cash_paid < self.total:

  return "Cash paid not enough"

else:

  return cash_paid - self.total


class Shop(ShoppingCart):

  def __init__(self):

self.quantity = 100

  def remove_item(self):

self.quantity -= 1

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


[Tutor] Tkinter Calendar to receive user entry.

2017-02-07 Thread Pooja Bhalode
Hi,

I am trying to create a calendar using tkinter GUI such that when the user
opens the GUI, it would show a drop down menu similar to the one seen on
flight websites for booking and then the user can select any specific date.
I need to make this such that the user can navigate between years and
months in the same window.

Can some one please help me with this? I looked up on the website, I came
across this one,
http://stackoverflow.com/questions/27774089/python-calendar-widget-return-the-user-selected-date
But when I try to run it, it gives me an error saying that it is not able
to recognize Calendar.

I would really appreciate some help with this. I also came to know that I
could use calendar.Calendar to create an object for the same, but I am not
good with working with objects and thus, not able to proceed or understand
how to link it up with GUI.

Please let me know.
Thankyou

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


[Tutor] Help Please on python

2017-02-07 Thread Laura Garcia
I need to create a python code that  should simulate throwing darts by
random landing between (a random x and a random y)0 and 1.  and the program
should print out number of darts that land within a rectangle.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor