Re: [Tutor] Python Help

2017-09-16 Thread Mats Wichmann
On 09/15/2017 10:25 AM, Alan Gauld via Tutor wrote:
> On 15/09/17 04:08, Pratyusha Thundena wrote:
>> How do check to see if string ‘garden’ contains a 
>> vowel(a, e , i , o, u , or y) using a for loop? 
> 
> Hi, this sounds like homework and we won't do
> your homework for you, but we do give hints.
> 
> How would you do this without a computer?
> There are (at least) two ways:
> 1) you can check each letter in your word and
>see if it is a vowel.
> 2) we can check each vowel and see if it is
>in your word
> 
> A for loop gives you each item in a sequence one
> by one so would work in either solution.
> 
> Let's consider option 1 in pseudo-code:
> 
> for each letter in word:
> if letter is a vowel:
>do something... what?
> 
> So that leads to two questions:
> 1) how do you tell if a letter is a vowel?
>Hint: look at what the string 'in' operator does
> 2) What do you want to do if you find a vowel?
>print something? exit? or what...?
> 
> See if that helps, if you still need help come back with
> a specific question (the more specific the question, the
> more specific will be the answer) and show us your code
> plus any error messages you received.

It also leads to a chance to lecture (just what you wanted, right):

Computer programming is hard.  One of the reasons it's hard is because
you don't always know exactly what the problem you're trying to solve
consists of. Here in a learning situation it's going to be safe, but in
the real world you will often find what seemed obvious to the person who
framed the requirement may be full of ambiguities or subtle effects. Like:

Does a string contain a vowel? - you list the 5 1/2 vowels from English.

y is the 1/2: grammatically, it is considered a vowel in words like
'baby' or 'sky', but it is a consonant in words like 'yes' or 'yogurt'.
Should your solution take this into account? It would make the code
vastly more complicated, because you would have to teach it to divide
the word correctly into syllables, and apply the rule for when it is
treated as a consonant. Which means you probably need to start by
validating that the input is a correct word.  Of course you are not
going to worry about that solving a classroom problem (unless the
instructor or book is being very sneaky).

and then there is the complication of language.  should your solution
work for English only? Or for other languages? I grew up speaking a
language where åäö are vowels.  If you are trying to process information
entered by a user in a website, for example, there's a pretty reasonable
chance that it should understand other languages, and then you need to
look into character-set specifications, unicode, etc.

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


Re: [Tutor] Python HW question

2017-09-16 Thread Ben Finney
 writes:

> I really need some Python help. I’m a beginner and have some hw for
> class:

Welcome, and congratulations on beginning to learn Python!

> Write a program that calculates longest substring of increasing
> letters in st, say st=‘Supercalifragilisticexpialidocious’.

That is *very* brief. Do you at least understand what the problem is —
that is, can you re-state the requirement and explain it to someone else
(me)?

> I have no idea where to start this problem. Any help you can provide
> will be spectacular.

* Do you know how to “write a program” with Python, and run it
  successfully? I will assume you do know that.

* Can you show a Python statement that “uses the comparison ‘<=’ to
  check if one letter is greater than another”?

* Can you show a “loop through all possible starting positions of a
  sub-string” in a larger string?

-- 
 \   “If you always want the latest and greatest, then you have to |
  `\  buy a new iPod at least once a year.” —Steve Jobs, MSNBC |
_o__) interview 2006-05-25 |
Ben Finney

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


Re: [Tutor] Python HW question

2017-09-16 Thread Alan Gauld via Tutor
On 16/09/17 01:32, mikn...@gmail.com wrote:

> I really need some Python help. I’m a beginner and have some hw for class:

OK, Usual caveat: we don;t do your homework, just give hints.

> Write a program that calculates longest substring of increasing letters in 
> st, say st=‘Supercalifragilisticexpialidocious’. Do it in a few steps:

I'm assuming that means a string where each letter is higher
than the previous one, such as 'best'?

> 1.Find longest increasing substring starting from 0th position, 
> use comparison <= to check if one letter greater than other

You don't tell us about how much Python or programming
experience you have so I'll assume its near zero and
apologize if I'm pitching too low.

Do you know how to write some code to check each letter
in a string, one by one? If so could you write a short
program to test whether a string is increasing? ie start
at the beginning and check whether each letter is greater
than the previous one.

If you can do that then the rest of the homework
becomes much easier.

Do you know how to define your own function? If so that
will also make things slightly simpler.

> 2. Use function len of object str(ing) to find length of string
> 3.Write one line of code that choses longest string from 2

If you can do 2 then 3 is trivial.

For example if we have two strings:

s1 = 'Python'
s2 = 'Perl'

Can you write code to display the lengths of s1 and s2?
Can you then write a single line of code that chooses
which string is longesst?

> 4. Loop through all possible starting position start> of the str, and find 
> longest increasing substring of st.

This is combining step 1 with steps 2 and 3.

> I have no idea where to start this problem. 

Start with 1 above. Write some code to determine if a
string is an increasing string. If you know how put
it in a function, but that's a nice to have...

If you get stuck come back here and show us the code
and any error messages you get. We'll try to help you
fix 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


[Tutor] Python HW question

2017-09-16 Thread miknau1
Good evening,

I really need some Python help. I’m a beginner and have some hw for class:

Write a program that calculates longest substring of increasing letters in st, 
say st=‘Supercalifragilisticexpialidocious’. Do it in a few steps:
1.Find longest increasing substring starting from 0th position, use comparison 
<= to check if one letter greater than other
2. Use function len of object str(ing) to find length of string
3.Write one line of code that choses longest string from 2
4. Loop through all possible starting position start of the str, and find 
longest increasing substring of st.

I have no idea where to start this problem. Any help you can provide will be 
spectacular.

Thanks,

Mikhail

Sent from Mail for Windows 10

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


Re: [Tutor] array input from keyboard

2017-09-16 Thread Oliver Schmitz
Hi Derek,

you are iterating over the input string, this will result in single
chars in each iteration of your for loop.

You could use `split` on your string to split the string into a list,
splitted by comma.

Instead of:

>vols = []
>vols = input("Please enter your volume ids, comma delimited? ")
>for vols in vols :
>vols = vols.rstrip()

Do the following:

vols = input("Please enter your volume ids, comma delimited? ")
for vol in vols.replace(" ", "").split(","):
# dome something with your vol

The creation of an empty list isn't needed.

You shouldn't name the element of the iteration the same as the object
you are iterating on. So instead of `for vols in vols` use for `vol in
vols` as inside the loop you are working on a single volume instead of
multiples.

The `replace` will remove all your whitespace (as it seems your strings
don't need/dont' want them). Next the `split` will split your input
elements comma seperated into a list for the iteration by the `for` loop.


Am 15.09.17 um 22:50 schrieb Derek Smith:
> I need to accept input from the user then store in an array/list.  This is my 
> 1st python script.
> 
> #!/usr/bin/env python
> # Derek Smith
> # 09/2017
> # accept volumes for TSM for tape mgmt.
> 
> import os
> import sys
> 
> nput1 = ""
> nput2 = ""
> nput1 = input("\nIs your input 'file' based or 'cli' based? ")
> 
> if nput1 == "file" :
> nput2 = input("Please provide your input file? ")
> nput2 = nput2.lower()
> print (nput2)
> fh = open(nput2,"r")
> 
> for ln in fh:
> ln = ln.rstrip()
> os.system("/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes 
> move drm %s" %ln, "tost=onsiter")
> os.system("/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes 
> move drm %s" %ln, "wherest=vaultr tost=onsiter")
> 
> elif nput1 == "cli" :
> vols = []
> vols = input("Please enter your volume ids, comma delimited? ")
> vols = vols.upper()
> for vols in vols :
> vols = vols.rstrip()
> print("/usr/bin/dsmadmc -id=dereksmith -password=dereksmith 
> -dataonly=yes move drm %s" %vols, "tost=onsiter")
> elif
> print ("Incorrect input, exiting.")
> sys.exit(99)
> 
> 
> __OUTPUT__
> 
> # python tsm_moveVR_tonsiter.py
> 
> Is your input 'file' based or 'cli' based? cli
> Please enter your volume ids, comma delimited? r20344l5,r20355l5
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm R 
> tost=onsiter
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 2 
> tost=onsiter
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 0 
> tost=onsiter
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 3 
> tost=onsiter
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 4 
> tost=onsite
> ...
> ...
> ...
> 
> Its printing each element per line.  I have tried various changes, read 
> online help but gave up looking.
> I need it to print as below:
> 
> 
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm R20344L5 
> tost=onsiter
> /usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm R20355L5 
> tost=onsiter
> 
> Thank you!!
> Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
> ::  dereksm...@racksquared.com  *: 
> www.racksquared.com |  
> www.racksquared.jobs
> 
> [cid:image003.png@01D2E9AA.1B9CF8F0]
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

Regards,
Oliver Schmitz


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


Re: [Tutor] Python + Irc

2017-09-16 Thread Oliver Schmitz
Hi Fernando,

i guess the most popular and feature-rich IRC library for python is
(guess how it is named ...) irc by jaraco.

pypi: https://pypi.python.org/pypi/irc
github: https://github.com/jaraco/irc

If you want to build something more advanced (quite difficult for
beginners) on your own, you could have a look at twisted's IRC protocol
implementation:
http://twistedmatrix.com/documents/current/api/twisted.words.im.ircsupport.html

Twisted is quite impressive and performant, but as it is event-based, it
is more difficult to implement and for most usecases, this would be
overkill. Nevertheless it's great ;).

Am 15.09.17 um 22:16 schrieb Fernando Gualberto:
> How i can integrate Python program with IRC to send Messages from program
> to the IRC?
> 

Regards,
Oliver Schmitz

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