Re: [Tutor] how do I set variables in Python 3.4

2014-07-14 Thread wesley chun
Greetings Danielle,

Welcome to programming! Thanks for the additional clarification as to what
your project is. Starting from scratch isn't easy, but with a little bit of
guidance, you'll soon be able to "drive on your own!"

In the course you're taking, can you share a bit about what resources your
instructor has provided you? Is there a book or an online website that
you're using? From looking at the code you've created, it seems that you're
trying to just take the requirements and hoping that it matches with the
languages syntax. Because it does *not*, the Python interpreter cannot
figure out what you're trying to do.

The solution is to learn the language that the Python interpreter is
"speaking," and converse in that language to help you meet your goal. For
example, the book or website that you're using should be indicating that
when the requirement is: "Set operand1 = 2 and operand2 = 7," this does not
mean that 'set "(operand1 = 2 and operand2 = 7)"' is what you would do in
Python.

The reading should have told you that "set" is not a keyword in Python.
Instead, you would think, "I need to set these variables... how do I do
that?" In your study guide, you would then find something like: "In order
to assign a value to a variable in Python, for example, to assign the
integer 10 to the variable 'x', the correct syntax is: x = 10". You then
bring that back to your example and do something similar: "operand1 = 2".

In fact, all of us here on the mailing list would go a step further and ask
you to experiment, like set the variable and then display it, and to
cut-n-paste the output here so we can confirm you know how to do it, and
that it works:

>>> operand1 = 2
>>> print(operand1)
2
>>> print(1 + operand1)
3

Once you've gained some confidence, you can then do the same for operand2,
and after this, go back to your learning resource and learn how to add,
subtract, etc. The best part is that you only have to learn these steps
once. The rules don't change for this aspect of programming in Python, and
you can then go ahead and complete your assignment. The most important
thing is to reference your learning resource and not to guess based on the
requirements in the assignment. Check out all the examples and model your
solution after them.

Best of luck!
--Wesley


On Mon, Jul 14, 2014 at 10:51 PM, Danielle Salaz 
wrote:

> This is the assignment:
>
> Write a Python script as follows:
>
>
>
> Use 3 variables named:
>
>operand1
>
>operand2
>
>result
>
> Set operand1 = 2 and operand2 = 7.
>
>
>
> Evaluate the following expressions and produce the output as shown:
>
>result = operand1 + operand2
>
>result = operand2 – operand1
>
>result = operand2 * operand1
>
>result = operand2 / operand1
>
>result = operand2 % operand1
>
>
>
> Your output should look like:
>
>
>
>operand1 = 2
>
>operand2 = 7
>
>2 + 7 = 9
>
>7 – 2 = 5
>
>7 * 2 = 14
>
> etc.
>
>
> I am using Python 3.4 and my OS is Windows 7 Ultimate.
> Thank you everyone for all of your help
>
>
> On Sun, Jul 13, 2014 at 10:41 AM, Danny Yoo 
> wrote:
>
>> On Sun, Jul 13, 2014 at 12:25 AM, Danielle Salaz 
>> wrote:
>> > This is what I've been doing, also I'm using version 3.4
>> >
>> > set "(operand1 = 2 and operand2 = 7)
>> > print (operand1 = 2)
>> > print (operand2 = 7)
>> > print (result=operand1 + operand2)
>> > print (result=operand2 - operand1)
>> > print (result=operand2 * operand1)
>> > print (result=operand2 / operand1)
>> > print (result=operand2 % operand1)
>>
>>
>> Beyond what Alan has said, also please also also say what you expected
>> to happen if the program were to run without error.
>>
>> I mentioned this earlier in a prior reply in this thread, and I still
>> stick by the recommendation.  We want to help troubleshoot any
>> misconceptions as early as possible, and knowing intent is helpful.
>>
>> Since you are a beginner, try to explain each line and the overall
>> program goal if possible.  It will help us understand what programming
>> model you've got in your head.  For example, can you explain what the
>> first three lines of your program are intended to do?
>>
>
>
>
> --
> Thank you,
> Danielle Salaz
> Signature Financial Services, Inc.
> 21 W. Laurel Dr. #47, Salinas, Ca. 93906
> (831) 754-0600
>
> Your perception has everything to do with your progression!!
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
+wesley chun  : wescpy at gmail : @wescpy

Python training & consulting : http://CyberwebConsulting.com
"Core Python" books : http://CorePython.com
Python blog: http://wescpy.blogspot.com
___
Tut

Re: [Tutor] how do I set variables in Python 3.4

2014-07-14 Thread Danielle Salaz
This is the assignment:

Write a Python script as follows:



Use 3 variables named:

   operand1

   operand2

   result

Set operand1 = 2 and operand2 = 7.



Evaluate the following expressions and produce the output as shown:

   result = operand1 + operand2

   result = operand2 – operand1

   result = operand2 * operand1

   result = operand2 / operand1

   result = operand2 % operand1



Your output should look like:



   operand1 = 2

   operand2 = 7

   2 + 7 = 9

   7 – 2 = 5

   7 * 2 = 14

etc.


I am using Python 3.4 and my OS is Windows 7 Ultimate.
Thank you everyone for all of your help


On Sun, Jul 13, 2014 at 10:41 AM, Danny Yoo  wrote:

> On Sun, Jul 13, 2014 at 12:25 AM, Danielle Salaz 
> wrote:
> > This is what I've been doing, also I'm using version 3.4
> >
> > set "(operand1 = 2 and operand2 = 7)
> > print (operand1 = 2)
> > print (operand2 = 7)
> > print (result=operand1 + operand2)
> > print (result=operand2 - operand1)
> > print (result=operand2 * operand1)
> > print (result=operand2 / operand1)
> > print (result=operand2 % operand1)
>
>
> Beyond what Alan has said, also please also also say what you expected
> to happen if the program were to run without error.
>
> I mentioned this earlier in a prior reply in this thread, and I still
> stick by the recommendation.  We want to help troubleshoot any
> misconceptions as early as possible, and knowing intent is helpful.
>
> Since you are a beginner, try to explain each line and the overall
> program goal if possible.  It will help us understand what programming
> model you've got in your head.  For example, can you explain what the
> first three lines of your program are intended to do?
>



-- 
Thank you,
Danielle Salaz
Signature Financial Services, Inc.
21 W. Laurel Dr. #47, Salinas, Ca. 93906
(831) 754-0600

Your perception has everything to do with your progression!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I set variables in Python 3.4

2014-07-13 Thread Danny Yoo
On Sun, Jul 13, 2014 at 12:25 AM, Danielle Salaz  wrote:
> This is what I've been doing, also I'm using version 3.4
>
> set "(operand1 = 2 and operand2 = 7)
> print (operand1 = 2)
> print (operand2 = 7)
> print (result=operand1 + operand2)
> print (result=operand2 - operand1)
> print (result=operand2 * operand1)
> print (result=operand2 / operand1)
> print (result=operand2 % operand1)


Beyond what Alan has said, also please also also say what you expected
to happen if the program were to run without error.

I mentioned this earlier in a prior reply in this thread, and I still
stick by the recommendation.  We want to help troubleshoot any
misconceptions as early as possible, and knowing intent is helpful.

Since you are a beginner, try to explain each line and the overall
program goal if possible.  It will help us understand what programming
model you've got in your head.  For example, can you explain what the
first three lines of your program are intended to do?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I set variables in Python 3.4

2014-07-13 Thread Alan Gauld

On 13/07/14 08:25, Danielle Salaz wrote:

This is what I've been doing, also I'm using version 3.4

set "(operand1 = 2 and operand2 = 7)


Do you by any chance have some Lisp or Scheme experience?
That looks like a Lispy kind of syntax...

Whatever, in Python you don't need to use words
like set or let when assigning values to names.
The above line is meaningless to Python,
hence the errors.

To assign a value you simply do the assignment directly.

operand1 = 2
operand2 = 7



print (operand1 = 2)


The print function displays output on the screen.
It converts its input (between the parentheses)
to strings for you. But it cannot do assignments.
Your print statement could look like

print(2)   # print a literal value

or

print(operand1)  # print a symbol's value


print (result=operand1 + operand2)


Again this is trying to print what is inside the parentheses
But it can't execute the assignment. You need to assign
outside the print (or just print the expression).
So you could do it like this:


print (operand1 + operands2)   # print() evaluates and prints result

or

result = operand1 + operand2
print(result)# just print the stored value


Traceback (most recent call last):
   File "C:/Python34/Assignment3_DanielleSalaz.py", line 1, in 
 print (operand1 = 2)
TypeError: 'operand1' is an invalid keyword argument for this function


See the comments above.

Its possible you have seen code that looks like this before but
that is due to a slightly confusing feature of Python.

Python functions have parameters. Some parameters have default
values so you don't always need to supply them. If you want to change 
one of these default values you can do it by assigning a value in the 
function call. But that is the only kind of assignment you are allowed 
to do, it must be to one of the functions defaulted parameters.


In this case the print function does not have a default parameter called 
operand1 so you cannot do an assignment to operand1 inside

the print function call. So although you might see code like

print(x,y,sep='-')

the sep assignment is a special operation specific to the print function
you cannot assign arbitrary values to arbitrary names inside the 
function. This is true of any function, not just print().


If you didn't understand those last 4 paragraphs don't worry, you
will get to it later in your course and all will become clear,
I hope. They were written on the assumption that you are coming
to python from another language such as Lisp...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
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] how do I set variables in Python 3.4

2014-07-13 Thread Danielle Salaz
I am using idle

Sent from my iPhone

> On Jul 11, 2014, at 1:50 PM, Alan Gauld  wrote:
> 
>> On 11/07/14 06:50, Danielle Salaz wrote:
>> I'm a noob to Python and cannot figure out how to complete one of my 
>> assignments.
>> 
>> I am supposed to use operand1=2 and operand2=7
>> To complete: result= operand1+operand2 etc, but
> 
> We need more detail.
> 
> How are you entering your code? Is it using a tool like
> IDLE or an operating system console version of python?
> 
> Are you typing at the interactive python prompt,
> usually looking like
> >>>
> 
> > I keep getting invalid syntax either on the " or operand1.
> 
> Please post the exact code you entered and the
> full error message, do not summarize.
> 
> There is no " in the little bit code you posted.
> And operand1 appears twice.
> We need to see exactly what you are doing - what you
> typed, and what Python told you was wrong.
> 
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I set variables in Python 3.4

2014-07-13 Thread Danielle Salaz
This is what I've been doing, also I'm using version 3.4

set "(operand1 = 2 and operand2 = 7)
print (operand1 = 2)
print (operand2 = 7)
print (result=operand1 + operand2)
print (result=operand2 - operand1)
print (result=operand2 * operand1)
print (result=operand2 / operand1)
print (result=operand2 % operand1)

Traceback (most recent call last):
  File "C:/Python34/Assignment3_DanielleSalaz.py", line 1, in 
print (operand1 = 2)
TypeError: 'operand1' is an invalid keyword argument for this function
>>> 

Sent from my iPhone

> On Jul 11, 2014, at 12:38 PM, William Ray Wing  wrote:
> 
>> On Jul 11, 2014, at 1:50 AM, Danielle Salaz  wrote:
>> 
>> I'm a noob to Python and cannot figure out how to complete one of my 
>> assignments.
> 
> Welcome to Python - I’d hope you’ve been monitoring this Tutor list for at 
> least a few days -
> 
>> I am supposed to use operand1=2 and operand2=7 
>> To complete: result= operand1+operand2 etc, but I keep getting invalid 
>> syntax either on the " or operand1. Please help
> 
> If you have been, you would see that we need to know which version of Python, 
> what operating system, and then see a complete copy and paste of the 
> traceback and the code you were executing.
> 
> In this case, that would be particularly relevant, because it would appear 
> that you have typo’d your iPhone e-mail since there is no " character 
> anyplace in any of the three assignment statements you have given us. Worse, 
> on an iPhone keypad, the “ character isn’t close to anything else you might 
> logically have used.
> 
> -Bill
> 
> 
> 
>> Sent from my iPhone
>> ___
>> 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] how do I set variables in Python 3.4

2014-07-12 Thread Steven D'Aprano
Hi Danielle, and welcome.

Others have already replied to your post, and I'm going to reply with 
pretty much the same answer:

Please help us to help you! We're not mind-readers, we need to see the 
actual error messages you get, and your actual code, not just a rough 
paraphrase of it.

When Python has an error to report, it will print a traceback like this:

py> x = 1
py> y = 1/(1-x)
Traceback (most recent call last):
  File "", line 1, in 
ZeroDivisionError: division by zero


It's important to copy and paste the whole traceback, starting with the 
first line "Traceback ..." to the end. Tracebacks often contain a lot of 
useful information to help debugging. (Although not always: one of the 
frustrations of programming is that sometimes the error messages aren't 
very useful.)

You say:

> I am supposed to use operand1=2 and operand2=7 

You should be able to use that *exactly* as it is (although putting 
spaces around the = sign is recommended):

py> operand1 = 2
py> operand2 = 7
py> result = operand1 + operand2
py> print(result)
9



> To complete: result= operand1+operand2 etc, but I keep getting invalid 
> syntax either on the " or operand1. Please help

We can't tell what you have mistyped if we don't know what you typed in 
the first place :-(

Regards,


Steve

On Thu, Jul 10, 2014 at 10:50:12PM -0700, Danielle Salaz wrote:
> I'm a noob to Python and cannot figure out how to complete one of my 
> assignments. 
> 
> I am supposed to use operand1=2 and operand2=7 
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax 
> either on the " or operand1. Please help
> 
> Sent from my iPhone
> ___
> 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] how do I set variables in Python 3.4

2014-07-11 Thread Alan Gauld

On 11/07/14 06:50, Danielle Salaz wrote:

I'm a noob to Python and cannot figure out how to complete one of my 
assignments.

I am supposed to use operand1=2 and operand2=7
To complete: result= operand1+operand2 etc, but


We need more detail.

How are you entering your code? Is it using a tool like
IDLE or an operating system console version of python?

Are you typing at the interactive python prompt,
usually looking like
>>>

> I keep getting invalid syntax either on the " or operand1.

Please post the exact code you entered and the
full error message, do not summarize.

There is no " in the little bit code you posted.
And operand1 appears twice.
We need to see exactly what you are doing - what you
typed, and what Python told you was wrong.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
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] how do I set variables in Python 3.4

2014-07-11 Thread William Ray Wing
On Jul 11, 2014, at 1:50 AM, Danielle Salaz  wrote:

> I'm a noob to Python and cannot figure out how to complete one of my 
> assignments. 
> 

Welcome to Python - I’d hope you’ve been monitoring this Tutor list for at 
least a few days -

> I am supposed to use operand1=2 and operand2=7 
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax 
> either on the " or operand1. Please help
> 

If you have been, you would see that we need to know which version of Python, 
what operating system, and then see a complete copy and paste of the traceback 
and the code you were executing.

In this case, that would be particularly relevant, because it would appear that 
you have typo’d your iPhone e-mail since there is no " character anyplace in 
any of the three assignment statements you have given us. Worse, on an iPhone 
keypad, the “ character isn’t close to anything else you might logically have 
used.

-Bill



> Sent from my iPhone
> ___
> 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] how do I set variables in Python 3.4

2014-07-11 Thread Mark Lawrence

On 11/07/2014 06:50, Danielle Salaz wrote:

I'm a noob to Python and cannot figure out how to complete one of my 
assignments.

I am supposed to use operand1=2 and operand2=7
To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either 
on the " or operand1. Please help



Please show us your code and the complete traceback.  Please use cut and 
paste, don't try typing it in by hand as this inevitably leads to mistakes.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: [Tutor] how do I set variables in Python 3.4

2014-07-11 Thread Danny Yoo
> I am supposed to use operand1=2 and operand2=7
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax 
> either on the " or operand1. Please help


Unfortunately, you've paraphrased the error message enough that we can
not reproduce the problem.  Since you're emailing on your phone, you
may want to reply when you're in front of your compute and are in a
position to do some copy-and-pasting.

Please copy and paste exactly what your entire program looks like.
Please copy and paste the exact contents of the error message and the
surrounding lines.  Also, please say what you expected your program to
do.



For example, let's pretend that I'm seeing a problem in my own
program.  Here's how I'd ask for help:

---
I'm seeing the following error in my program:

>>> percent(1, 0)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in percent
ZeroDivisionError: integer division or modulo by zero

Here is my program:

###
def percent(part, whole):
   return part / whole
###

I expected to see infinity here, but I'm seeing this error instead.
Can you help explain what I can do to get this value?
---

That is, show the error message, show the program content, and most
importantly, try to say what you expected to see.

It may be obvious to you what should happen, but sometimes it isn't
obvious!  Here, in this example, I'm pretending to be a crazy person
who believes in infinity.  :P  And that information is useful, because
there actually is a way of getting such a value:
http://stackoverflow.com/questions/7781260/how-can-i-represent-an-infinite-number-in-python.
If I left that part out, the answers I get from other people might be
entirely different or miss this possibility altogether.



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