[Tutor] Executing "if :" function on terminal

2017-09-05 Thread Nathan Kckaiyer
Dear Tutor,
i have just started learning python. I have repeatedly hit a road
block on my mac os terminal . Everytime i use the "if  :" command i
get syntax errors. i do not see any errors on text editor i am
following instructions from a book
Original input on editor
>>> a=2
>>> if a==2 :
print("correct")

Last login: Tue Sep  5 15:43:03 on ttys000
Solariss-MacBook:~ Solaris$
/var/folders/Db/DbSciGOcFmyQ3L+HyzOb5E+++TI/-Tmp-/Cleanup\ At\
Startup/test-526290211.381.py.command ; exit;
  File "/Users/Solaris/Desktop/test.py", line 1
Python 3.0.1 (r301:69597, Feb 14 2009, 19:03:52)
 ^
SyntaxError: invalid syntax
logout

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


Re: [Tutor] Executing "if :" function on terminal

2017-09-05 Thread Alan Gauld via Tutor
On 05/09/17 08:56, Nathan Kckaiyer wrote:

> i have just started learning python. I have repeatedly hit a road
> block on my mac os terminal . Everytime i use the "if  :" command i
> get syntax errors. 

The problem is that you are somehow executing the Python
interpreter prompt in the interpreter. WE need to know exactly how you
are running the code.

Its possible you are trying to execute the shell window of IDLE (or some
other IDE) or that you are copy/pasting too much code from one window to
another. But its impossible to guess.

You need to tell us *exactly* how you run your code.
What tools are you using? What buttons/menus you use etc.

 a=2
 if a==2 :
>   print("correct")

So far so good. That looks like you are typing into the
interactive mode of the Python interpreter. Now if you
just hit Return you should see "correct" being printed
on the screen.

> Solariss-MacBook:~ Solaris$
> /var/folders/Db/DbSciGOcFmyQ3L+HyzOb5E+++TI/-Tmp-/Cleanup\ At\
> Startup/test-526290211.381.py.command ; exit;
>   File "/Users/Solaris/Desktop/test.py", line 1
> Python 3.0.1 (r301:69597, Feb 14 2009, 19:03:52)
>  ^
> SyntaxError: invalid syntax

But this looks like an OS terminal of some kind trying
to execute a file called test.py

But that file does not contain the Python code above,
it includes the header printed by the interpreter in
interactive mode. That is not executable code and so
Python complains.

test.py should only contain:

a=2
if a==2 :
print("correct")


and nothing else.

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


[Tutor] I want to display Integral symbols

2017-09-05 Thread edmundo pierre via Tutor
I have been trying to display mathematics symbols on my Tkinter (using Python) 
project, but was not successful .I am trying  to compute integrals on my 
Tkinter project and will like to display this image on my 
tkinter:∫2xdx. Jupiter can display that symbol using sympy, but I can 
not display it in my Tkinter. Any help?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Help With Python Tasks

2017-09-05 Thread Ruth Hardy
Dear Sir or Madam 

I was wondering if you can help me please with these computer science tasks as 
I don’t know where to start:

First Task

Write code do the following things involving strings.  Wherever possible, you 
should try to incorporate functions/procedures, although they are not 
appropriate for all tasks.

Print a list of 20 random numbers one after the other vertically on the screen. 
 Half way through, use a user input request to pause printing until input is 
received.

Ask a user to enter two numbers, one after the other.  Your code should 
validate that you receive numbers and prompt the user appropriately.  For the:

first number, use try-except to ensure you have a floating point number; place 
a comment in you code about how this works
second number, use .isnumeric() to check you have an integer; place a comment 
in your code to explain why this only works for integers
Use a forced type conversion to turn both numbers into floats, divided one by 
the other and print the answer to 2 d.p.  You code should keep on asking for 
numbers until two have been received.

Ask the user to input a true/false value and convert the input to a Boolean 
(hint: I don’t think you can do a forced type conversion for this…)



Second Task 

Write a menu system based on functions where the main program loop is only 2 
lines long

Write a simple calculator program based around a menu loop.  You should be able 
to enter ‘number 1’ and ‘number 2’ which will be displayed on the screen every 
time the menu is redisplayed’; there should also be a clear screen function 
used to avoid the screen getting too cluttered.

The calculator menu should allow the user to:

enter values for ‘number 1’ and ‘number 2’
add ‘number 1’ and ‘number 2’
subtract ‘number 2’ from ‘number 1’
multiply ‘number 1’ and ‘number 2’
divide ‘number 1’ by ‘number 2’
exit cleanly 
You program must display an answer that the user can read after each 
calculation.


I would appreciate your help so much as I need to have a finished copy  of this 
code by tomorrow late morning !

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


Re: [Tutor] I want to display Integral symbols

2017-09-05 Thread Alan Gauld via Tutor
On 05/09/17 14:29, edmundo pierre via Tutor wrote:
> I have been trying to display mathematics symbols on my Tkinter (using 
> Python) project,
>  but was not successful 

So show us what you did. Its hard to figure out what's
gone wrong when we can't see your code.

And that includes telling us what kind of widget you
are trying to display this on. A Label? a Text? a Canvas?
Any of those are candidates but all have different ways
of doing it.

> .I am trying  to compute integrals on my Tkinter project and will like to 
> display this image on my tkinter:

> ∫2xdx.

Are you trying to display an image?
Or are you trying to display that as text?
If text you need to pick the right font, one that has
the integral sign included. You will also likely need
to do a fair bit of tweaking with font sizes and line
spacing.

>  Jupiter can display that symbol using sympy,> I can not display it in my 
> Tkinter.

We need more information.
As a minimum:
Which OS are you using?
Which Python version? (and distribution if it includes Jupiter)
What UI widget are you using?
Are you displaying an image or text?
If text which font are you using?

Finally what does your code look like?
What error messages(in full) do you get(if any) in the console?


-- 
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 With Python Tasks

2017-09-05 Thread Alan Gauld via Tutor
On 05/09/17 19:25, Ruth Hardy wrote:

> I was wondering if you can help me please with these computer science tasks

We can help, but we won;t do them for you.

> First Task
> 
> Write code do the following things involving strings.  Wherever possible, 
> you should try to incorporate functions/procedures, 
> 
> Print a list of 20 random numbers one after the other vertically on the 
> screen.

There are (at least) two ways to do this. One very easy but laborious,
the other much shorter and quicker.
Do you know what they are? Can you print 20 numbers (forget random for
now) on the screen?

> Half way through, use a user input request to pause printing until 
> input is received.

Do you know how to read user input?

> Ask a user to enter two numbers, one after the other.  

This is slightly ambiguous, but I'd assume they mean
you should ask for input twice.
Do you know how to store user input into a variable?
Do you know how to convert user input to a number?

> Your code should validate that you receive numbers and 
> prompt the user appropriately.  

Do you know how to validate/check that the received
input is a number? (there are several ways to do this,
I'm not sure how they expect you to tackle it, it depends
on what you've been taught so far)


For the:
> first number, use try-except to ensure you have a floating point number; 

OK, That answers my question. You can use try/except
to check the number is valid...

> place a comment in you code about how this works
> second number, use .isnumeric() to check you have an integer; 

OK, They tell you what to do here.
Personally I don;t like the isnumeric() technique but its
what they want you to do so do it...

> Use a forced type conversion to turn both numbers into floats, >divided one 
> by the other and print the answer to 2 d.p.

Do you know how to print a number so it shows two dp?

> You code should keep on asking for numbers until two have been received.

OK, Lets just get it working for a single pair of numbers first.
Done that? Good, so now wrap it in a loop. What kind of loop will
work here?

> Ask the user to input a true/false value and convert th> input to a Boolean 
> (hint: I don’t think you can do a forced
> type conversion for this…)

The hint is correct.
How would you do it without a type conversion?

> Second Task 

Let's leave this task to another email.

See if you can answer the questions above.
If you can you should be able to join the bits together to get
the task completed. If not come back to us with specific
issues sand we'll explain a bit more.

Show us your code plus any error messages you get.

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


[Tutor] Select a string

2017-09-05 Thread Pat Martin
Hello all,

I am trying to write a program for a programming class that finds the
number of a specific string (bob) in a string of characters. I am using one
of the sample strings they give me and it should find 2 instances of bob
but my script returns 0. Since they want it to find 2 from the bobob in the
string using "bob in s" doesn't work (it only returns 1). My eyes are
crossing looking at the code, can someone give me a hint on what I am
missing that causes this to not give me the correct answer of 2.

#!/usr/bin/env python3

s = 'azcbobobegghakl'

count = 0
theo = False
firstb = False

for i in s:
if i == 'b':
firstb == True
if (i == 'b') and (theo == True):
count += 1
if (i =='o') and (firstb == True):
theo = True
if (i != 'b') and (i != 'o'):
theo = False
firstb = False


print(count)

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


Re: [Tutor] Select a string

2017-09-05 Thread Ben Finney
Pat Martin  writes:

> My eyes are crossing looking at the code, can someone give me a hint
> on what I am missing that causes this to not give me the correct
> answer of 2.

It's good to admit that looking at the code has ceased to help :-)

So, try a different approach. Without using the code, can you describe
your algorithm? Make a pseudo-code description of how you expect to
transform the input to the output.

For example, I might describe the algorithm for reversing a text
string::

* Given a text string named ‘input_text’
* Set the output, named ‘output_text’, to the value "".
* Set the index (named ‘index’) to the character length of ‘input_text’.
* While ‘index’ is greater than 0:
  * Subtract 1 from ‘index’.
  * Get the character at index ‘index’ of ‘input_text’, assign the
name ‘input_char’ to that character.
  * Append ‘input_char’ to ‘output_text’.
* Return the value of ‘output_text’.

Can you describe your algorithm that way, so we can see what is your
intention for the code?

-- 
 \   “Faith is the determination to remain ignorant in the face of |
  `\ all evidence that you are ignorant.” —Shaun Mason |
_o__)  |
Ben Finney

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


Re: [Tutor] Select a string

2017-09-05 Thread Cameron Simpson

On 05Sep2017 22:34, Pat Martin  wrote:

I am trying to write a program for a programming class that finds the
number of a specific string (bob) in a string of characters. I am using one
of the sample strings they give me and it should find 2 instances of bob
but my script returns 0. Since they want it to find 2 from the bobob in the
string using "bob in s" doesn't work (it only returns 1). My eyes are
crossing looking at the code, can someone give me a hint on what I am
missing that causes this to not give me the correct answer of 2.

#!/usr/bin/env python3

s = 'azcbobobegghakl'

count = 0
theo = False
firstb = False

for i in s:
   if i == 'b':
   firstb == True


This line is a boolean expression using "==", not an assignment using "=". As a 
consequence firstb is never set to True and the rest of the logic never fires.


It is legal in Python to just put an expression on a line.

It is usually worth putting in print() calls to debug things like this. I put:

 print(i, firstb, theo, count)

at the start of the loop and learned that firstb never becomes true. I also put 
the same print statement at the bottom.


The advantage of hte above print statement is that it shows you the character 
from the string along with each set of values. That way you can scan down the 
output to the "bob" part and look for correct behaviour.


I that hadn't helped I've have stuck print after each "if" until the problem 
became glaringly obvious.


BTW, it isn't good to write tests like:

 if theo == True:

"theo" a Boolean anyway. Just say:

 if theo:

It reads more naturally as well.

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor