Re: [Tutor] calling function

2017-11-27 Thread Alan Gauld via Tutor
On 27/11/17 20:47, Howard Lawrence wrote:
> import turtle
> # this part draws a square
> def square():
> 
> my_turtle = turtle.Turtle()

Note that this creates my_turtle as a local
variable inside the function. It will not
be visible outside the function.

> my_turtle.forward(100)
> my_turtle.left(90)
> my_turtle.forward(100)
> my_turtle.left(90)
> my_turtle.forward(100)
> my_turtle.left(90)
> my_turtle.forward(100)
> square()
> 
> my_turtle.forward(100)

So this should fail; with an error message
 - a name error most likely.

> # this is a second square
> square()

And this creates a new square directly on top of
the earlier one, so they look like one.

You need to create the turtle outside the function
and then refer to it from inside the function,
ideally by passing it in as an argument:


def square(aTurtle):
aTurtle.forward(100)
etc...

my_turtle = turtle.Turtle()
square(my_turtle)
my_turtle.forward(100)
square(my_turtle)

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] failed installation of Python 2.7

2017-11-27 Thread marcus lütolf
many thanks, Peter
I could install the newest version of python 3.6 without
any problems but I need python 2.7 for tutorial purposes.
Marcus.

 

-Ursprüngliche Nachricht-
Von: peter [mailto:peterrisle...@gmail.com] 
Gesendet: Montag, 27. November 2017 20:20
An: marcus lütolf 
Betreff: Re: [Tutor] failed installation of Python 2.7

I had that problem and ended up using install python3 instead of 3.6 . I do not 
think that was the best answer as now python3 defaults to 3.5.4 and not 3.6! 
frustrating. Its suppose to install and default to the newest version you have! 
but it works. also I remember that it did install 2.7 which for backward 
compatible issues is necessary I guess?

I think your problem is baked in the cake and we will have to wait till newer 
versions come out. And as they say "Waiting is the hardest part!" 
Tom petty.


On 11/26/2017 02:29 AM, marcus lütolf wrote:
> dear experts,
>
> cleaning up my computer I removed all my different Python versions,
>
> saving all .py and .txt files.
>
> I could reinstall Python 3.6 but not Python 2.7, getting an error mesage:
>
> ‚a program required for this insatll could not be found‘.
>
> Searching different websites I could not solve this problem.
> Might you be able to offre a solution?
>
>
>
> Marcus Luetolf
>
>   
>
>
>
> ---
> Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
> https://www.avast.com/antivirus
> ___
> 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] get javascript output data from ssi file

2017-11-27 Thread Derek Smith
I have not found a way into my tape library from the manufacture IBM, there's 
no command-line or api I am aware of nor is google. I need to get what this 
library thinks is its tape volumes inventory.  I have used chrome to view the 
code and its using adobe's SSI files which then calls a jscript.  Does python 
provide any way into this tricky application?  I tried cURL but from my 
understanding it will not provide such data since its pulls markup.  Below is 
the code in a file called move_element_operations.ssi according to chromes 
inspect command via right-click.  The volume listing and volumes are 
highlighted.

Thx in advance!!









function actionConfirm()
{
return 
confirm('Are you sure?');
}

function 
actionSamePartitionConfirm(source,destination)
{
/* different 
logocal libraries, no mailslot to mailslot move */
if( (source[3] 
!= destination[3])

&& !((source[1].toUpperCase() == "M") && (destination[1].toUpperCase() == "M"))

&& !(destination[1].toUpperCase() == "M") && (source[3] != 9))
{

return confirm( "Movement between Partitions, are you sure?" );
}
else return 
true;
}

function preMoveCheck()
{
//get currently 
selected items
destIndex = -1;
sourceIndex = 
-1;
while( 
document.getElementsByName("unique_table_radio1")[++sourceIndex].checked == 
false )
{

if( document.getElementsByName("unique_table_radio1")[sourceIndex + 1] == null )

{

sourceIndex = -1;

break;

}
}
while( 
document.getElementsByName("unique_table_radio0")[++destIndex].checked == false 
)
{

if( document.getElementsByName("unique_table_radio0")[destIndex + 1] == null )

{

destIndex = -1;

break;

}
}

if( 
(sourceIndex > -1) && (destIndex > -1) )
{

//extract data

var searchString = /([A-Z])(\d+)_(\d)_(\d)/;

source = searchString.exec( 
document.getElementsByName("unique_table_radio1")[sourceIndex].value );

destination = searchString.exec( 
document.getElementsByName("unique_table_radio0")[destInd

[Tutor] calling function

2017-11-27 Thread Howard Lawrence
import turtle
# this part draws a square
def square():

my_turtle = turtle.Turtle()
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
my_turtle.left(90)
my_turtle.forward(100)
square()

my_turtle.forward(100)

# this is a second square
square()

   # my_turtle.forward(100)
   # my_turtle.left(90)
   # my_turtle.forward(100)
   # my_turtle.left(90)
   # my_turtle.forward(100)
   # my_turtle.left(90)
   # my_turtle.forward(100)



what is wrong with this, and how to fix it
the code is suppose to make two box but only make one
using python 3.5 idle on windows 7
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help fixing some code for a project

2017-11-27 Thread Alan Gauld via Tutor
On 27/11/17 01:57, John Cocks wrote:
> The task is broken down into three sections.

What exactly do you want help with?
Do you not understand part of the problem?
Do you not know how to code some part?
Are you getting an error? If so show us the full error text.

WE are not mind readers, you need to tell us what
you want to know.

As for the code below, I've added a few remarks...

> #Task: Create the empty data structure
> grocery_item = {}
> 
> grocery_history = []
> 
> #Variable used to check if the while loop condition is met
> stop = 'go'
> 
> while stop == 'go' :

This would read better if stop were a boolean variable

stop = False
while not stop:
...


> #Accept input of the name of the grocery item purchased.
> item_name = "Item name:\n"

Your comment says "accept input" but you are not accepting
input, you are just assigning a string to a variable.
Do you know how to read input from a user?


> #Accept input of the quantitiy of the grocery item purchased.
> quantity = "Quantity purchased:\n"
> #Accept input of the cost of the grocery item input (this is a per-item
> cost).
> cost = "Price per item:\n"
> #Create a dictionary entry which contains the name, number and price
> entered by the user.
> grocery_item = {'name': item_name, 'number': int(quantity), 'price':
> float(cost)}  -- errors usually occur here because of "quantity
> purchased:\n line
> #Add the grocery_item to the grocery_history list using the append
> function
> grocery_history.append(grocery_item)
> #Accept input from the user asking if they have finished entering
> grocery items.
> print("Would you like to enter another item?\n Type 'c' for continue or
> 'q' to quit:\n")

If you were reading input how would you exit the while loop above?
You need to test for that situation and take the appropriate action.

> # Define variable to hold grand total called 'grand_total'
> grand_total = 0

Its traditional to put ALL the variable definitions at the top
of your code so you know where to find them easily.

> #Define a 'for' loop.
> for grocery_item in grocery_history:

Its probbablyt not a good idea to use the same variable
name for the loop as you did in the input code above.
In this case it won't bite you but it could get
confusing. I'd suggest maybe just use 'item' instead?


>   #Calculate the total cost for the grocery_item.
>   item_total = number * price

You don't have variables called 'number' or 'price'
but you do have dictionary keys in grocery_item.
So you really need:

item_total = grocery_item['number'] * grocery_item['price']

>   #Add the item_total to the grand_total
>   item_total = grand_total

You are not adding you are assigning. And in fact
you are wiping out your total by replacing it with 0!

>   #Output the information for the grocery item to match this example:
>   #2 apple @ $1.49 ea $2.98
>   print('number', 'name', 'price', 'cost')

Her you just print the key strings not the actuial values.
Again you need to use the keys to access the item.

>   #Set the item_total equal to 0
>   item_total = 0
> #Print the grand total
> print(grand_total)


HTH, but, if you have more specific queries, come back to
us with more detail.

-- 
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


[Tutor] Need help fixing some code for a project

2017-11-27 Thread John Cocks
The task is broken down into three sections.
Section 1 - User Input
Section 2 - loop through the grocery list
Section 3 - provide output to the console
'''

#Task: Create the empty data structure
grocery_item = {}

grocery_history = []

#Variable used to check if the while loop condition is met
stop = 'go'

while stop == 'go' :

#Accept input of the name of the grocery item purchased.
item_name = "Item name:\n"
#Accept input of the quantitiy of the grocery item purchased.
quantity = "Quantity purchased:\n"
#Accept input of the cost of the grocery item input (this is a per-item
cost).
cost = "Price per item:\n"
#Create a dictionary entry which contains the name, number and price
entered by the user.
grocery_item = {'name': item_name, 'number': int(quantity), 'price':
float(cost)}  -- errors usually occur here because of "quantity
purchased:\n line
#Add the grocery_item to the grocery_history list using the append
function
grocery_history.append(grocery_item)
#Accept input from the user asking if they have finished entering
grocery items.
print("Would you like to enter another item?\n Type 'c' for continue or
'q' to quit:\n")

# Define variable to hold grand total called 'grand_total'
grand_total = 0
#Define a 'for' loop.

for grocery_item in grocery_history:

  #Calculate the total cost for the grocery_item.
  item_total = number * price
  #Add the item_total to the grand_total
  item_total = grand_total
  #Output the information for the grocery item to match this example:
  #2 apple @ $1.49 ea $2.98
  print('number', 'name', 'price', 'cost')
  #print(name)
  #print(price: %6.2f) -- errors happen here
  #print(item_total: %6.2f) -- errors happen here too

  #Set the item_total equal to 0
  item_total = 0
#Print the grand total
print(grand_total)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor