Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54918 > unrolled thread

Help me with Python please (picture)

Started byjae655@gmail.com
First post2013-09-27 17:43 -0700
Last post2013-09-28 17:16 +0000
Articles 11 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  Help me with Python please (picture) jae655@gmail.com - 2013-09-27 17:43 -0700
    Re: Help me with Python please (picture) Gary Herron <gary.herron@islandtraining.com> - 2013-09-27 18:11 -0700
    Re: Help me with Python please (picture) Dave Angel <davea@davea.name> - 2013-09-28 01:18 +0000
    Re: Help me with Python please (picture) Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-28 02:18 +0000
    Re: Help me with Python please (picture) John Ladasky <john_ladasky@sbcglobal.net> - 2013-09-27 21:03 -0700
    Re: Help me with Python please (picture) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-28 05:18 +0000
      Re: Help me with Python please (picture) Chris Angelico <rosuav@gmail.com> - 2013-09-28 15:46 +1000
    Re: Help me with Python please (picture) dvghana@gmail.com - 2013-09-28 09:17 -0700
      Re: Help me with Python please (picture) Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-28 12:50 -0400
        Re: Help me with Python please (picture) Bob Martin <bob.martin@excite.com> - 2013-09-29 08:07 +0100
      Re: Help me with Python please (picture) Dave Angel <davea@davea.name> - 2013-09-28 17:16 +0000

#54918 — Help me with Python please (picture)

Fromjae655@gmail.com
Date2013-09-27 17:43 -0700
SubjectHelp me with Python please (picture)
Message-ID<7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com>
http://imgur.com/E6vrNs4


Can't seem to be getting an output.

[toc] | [next] | [standalone]


#54919

FromGary Herron <gary.herron@islandtraining.com>
Date2013-09-27 18:11 -0700
Message-ID<mailman.398.1380330996.18130.python-list@python.org>
In reply to#54918
On 09/27/2013 05:43 PM, jae655@gmail.com wrote:
> http://imgur.com/E6vrNs4
>
>
> Can't seem to be getting an output.

Please find a way to include the code in the email.   Also what evidence 
do you provide that it does not work?  What happened when you ran it?  
What did you expect to happen?  What were you trying to achieve?

Since you are asking volunteers to help, it would be polite to take the 
time to explain things carefully.


Gary Herron

[toc] | [prev] | [next] | [standalone]


#54920

FromDave Angel <davea@davea.name>
Date2013-09-28 01:18 +0000
Message-ID<mailman.399.1380331126.18130.python-list@python.org>
In reply to#54918
On 27/9/2013 20:43, jae655@gmail.com wrote:

> http://imgur.com/E6vrNs4
>
>
> Can't seem to be getting an output.

Please compose a text message containing a description of the
environment, the (small) code, and the expected results. This is a text
mailing list, and posting transient images on untrusted websites is
not likely to get you much help.

And when copying the code and the output, please use cut and paste; 
don't paraphrase or retype anything.

if you don't know how to capture the text, describe your environment,
and somebody will probably be able to help you.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#54922

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-09-28 02:18 +0000
Message-ID<l25ea3$eh4$1@dont-email.me>
In reply to#54918
On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote:

> http://imgur.com/E6vrNs4

> Can't seem to be getting an output.

I can't see where your output statements are.

With no output statements, there is no output.

perhaps you want to assign the result of the function call to a variable, 
and then print the variable? Or perhaps not, perhaps you were going to do 
the output some other way?

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#54923

FromJohn Ladasky <john_ladasky@sbcglobal.net>
Date2013-09-27 21:03 -0700
Message-ID<e4876b23-11c4-432e-a3d6-32bcc8af750e@googlegroups.com>
In reply to#54918
On Friday, September 27, 2013 5:43:42 PM UTC-7, jae...@gmail.com wrote:
> http://imgur.com/E6vrNs4
> 
> Can't seem to be getting an output.

Because you aren't printing anything!

One possible way to fix that is to change the line which reads...

random_characters(8)

to read...

print(random_characters(8))

instead.

[toc] | [prev] | [next] | [standalone]


#54925

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-09-28 05:18 +0000
Message-ID<5246668d$0$30000$c3e8da3$5496439d@news.astraweb.com>
In reply to#54918
On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote:

> http://imgur.com/E6vrNs4
> 
> 
> Can't seem to be getting an output.

The problem with your code has to do with the code between pixel 
coordinates (29, 234) and (175, 249) approximately. If you open your 
image in a pixel editor, copy and paste that part out, run it through 
some OCR software, and then add "print " (including the space) before it, 
you will probably get the result you are after.

By the way, posting a picture of your code is thoughtless and rude to 
those contributors and programmers who are blind or partially sighted. If 
you post text, they can contribute using a screen-reader. If you post a 
picture, they're screwed. Even if you don't give two hoots for the blind, 
at least consider that maybe they can answer your question when nobody 
else can.

Why would we want to follow a link to look at your code, when we could 
read it right here in your message? We might not have access to imgur 
(many places block it). We cannot copy and paste your code to run it to 
see what it does, or make edits to it. If we want to describe parts of 
your code we have to re-type it, possibly introducing our own typos.

I really don't understand why you would take program code, which is text, 
and take a screenshot of it, then spend time blanking out parts of the 
screenshot. Text is *much* more useful for a programmer. It astonishes me 
that there is an entire subreddit on imgur dedicated to people who take 
screenshots of their code. What's wrong with them?

Could be worse -- at least you didn't take a photo of the screen with 
your phone, them email the picture to yourself, then take a screenshot of 
the photo in your mail client, then upload that screenshot to imgur, then 
take a screenshot of the picture on imgur, then post that screenshot here.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#54926

FromChris Angelico <rosuav@gmail.com>
Date2013-09-28 15:46 +1000
Message-ID<mailman.401.1380347180.18130.python-list@python.org>
In reply to#54925
On Sat, Sep 28, 2013 at 3:18 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Could be worse -- at least you didn't take a photo of the screen with
> your phone, them email the picture to yourself, then take a screenshot of
> the photo in your mail client, then upload that screenshot to imgur, then
> take a screenshot of the picture on imgur, then post that screenshot here.

http://xkcd.com/763/

ChrisA

[toc] | [prev] | [next] | [standalone]


#54951

Fromdvghana@gmail.com
Date2013-09-28 09:17 -0700
Message-ID<1f5d2dd8-877d-4d80-b3c3-d5a048556061@googlegroups.com>
In reply to#54918
On Saturday, September 28, 2013 12:43:42 AM UTC, jae...@gmail.com wrote:
> http://imgur.com/E6vrNs4
> 
> 
> 
> 
> 
> Can't seem to be getting an output.

All the comments about using an image to ask for help over here is extremely valid so I hope you accept it in good faith. I am a noob like you so I can tolerate it and see if I can help you.

So here we  go:
1. random.randit will only return an integer but it sounds to me like you are trying to return one of the elements in "chars"

If my understanding is correct try using random.choice instead.

To return a random character from the alphabets you can try:

>> import string
>> char = random.choice(string.ascii_lowercase) 
   #string.ascii_uppercase for uppercace

2. you may not need the main() function.
and you didn't have any 'print' statement so when you run the code you won't see anything. You are simply generating random characters and throwing them away

try:
print (random_characters(8))

3. but if you run the code as it stands it won't generate 8 random charaters so you'll actually have to be appending it on a list.

So instead of:
new_string = ''
try:
new_string = []

4. Finally, join the elements in the list once they are generated like this:
    return "".join(new_string)
but don't forget to append each character anytime the loop runs this way:
    new_string.append(random.choice(string.ascii_lowercase))
    
Overall I wrote my own version of the code and this is what I got:


******************
import string
import random

def random_characters(number):
    i = 0
    new_string = []

    while (i < number) :
        new_string.append(random.choice(string.ascii_lowercase))
        i = i + 1
    return "".join(new_string)


print(random_characters(3))
*******

[toc] | [prev] | [next] | [standalone]


#54955

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-09-28 12:50 -0400
Message-ID<mailman.421.1380387020.18130.python-list@python.org>
In reply to#54951

[Multipart message — attachments visible in raw view] — view raw

On Sat, Sep 28, 2013 at 12:17 PM, <dvghana@gmail.com> wrote:

> On Saturday, September 28, 2013 12:43:42 AM UTC, jae...@gmail.com wrote:
> > http://imgur.com/E6vrNs4
> >
> >
> >
> >
> >
> > Can't seem to be getting an output.
>
> All the comments about using an image to ask for help over here is
> extremely valid so I hope you accept it in good faith. I am a noob like you
> so I can tolerate it and see if I can help you.
>
> So here we  go:
> 1. random.randit will only return an integer but it sounds to me like you
> are trying to return one of the elements in "chars"
>
> If my understanding is correct try using random.choice instead.
>
> To return a random character from the alphabets you can try:
>
> >> import string
> >> char = random.choice(string.ascii_lowercase)
>    #string.ascii_uppercase for uppercace
>
> 2. you may not need the main() function.
> and you didn't have any 'print' statement so when you run the code you
> won't see anything. You are simply generating random characters and
> throwing them away
>
> try:
> print (random_characters(8))
>
> 3. but if you run the code as it stands it won't generate 8 random
> charaters so you'll actually have to be appending it on a list.
>
> So instead of:
> new_string = ''
> try:
> new_string = []
>
> 4. Finally, join the elements in the list once they are generated like
> this:
>     return "".join(new_string)
> but don't forget to append each character anytime the loop runs this way:
>     new_string.append(random.choice(string.ascii_lowercase))
>
> Overall I wrote my own version of the code and this is what I got:
>
>
> ******************
> import string
> import random
>
> def random_characters(number):
>     i = 0
>     new_string = []
>
>     while (i < number) :
>         new_string.append(random.choice(string.ascii_lowercase))
>         i = i + 1
>     return "".join(new_string)
>
>
> print(random_characters(3))
> *******
> --
> https://mail.python.org/mailman/listinfo/python-list
>

 I'm guessing this is homework since its kind of a contrived exercise.  If
you do any reading of python tutorials or books for beginners I don't
think  you will see this sort of loop used in python:

   while i < number:
      do_something ...
      i += 1

This is even weirder:

  while (i < number):



Its not that you can't do that.  But it is much more common to see in other
languages (like C or maybe PHP, others ?).  So either the instructor is
promoting this kind of loop because he knows a little about another
language and not so much about python,  or the student has some knowledge
of another language.

I prefer:
  for i in range(number):
      do_something...


and finally

plus + on the calling out of using images to post code.  I'm guessing the
OP is a computer user in the sense of running word, or watching you-tube
videos, etc.  Most non-programmers never used a plain text editor.   If you
want to learn how to write code, and you are a beginner, use the simplest
text editor on your computer, learn to open a shell and run python
interactively and run programs that you saved with your text editors.  Be
glad for simplicity.  And happy you don't write code on these:
http://en.wikipedia.org/wiki/Hollerith_cards


-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#54983

FromBob Martin <bob.martin@excite.com>
Date2013-09-29 08:07 +0100
Message-ID<baq1ucFs81vU1@mid.individual.net>
In reply to#54955
in 706312 20130928 175017 Joel Goldstick <joel.goldstick@gmail.com> wrote:
>--047d7bf0f67adc8dbc04e7746532
>Content-Type: text/plain; charset=UTF-8
>

Please don't post HTML.

[toc] | [prev] | [next] | [standalone]


#54959

FromDave Angel <davea@davea.name>
Date2013-09-28 17:16 +0000
Message-ID<mailman.424.1380388639.18130.python-list@python.org>
In reply to#54951
On 28/9/2013 12:17, dvghana@gmail.com wrote:

> On Saturday, September 28, 2013 12:43:42 AM UTC, jae...@gmail.com wrote:
 
 
>> 
>> 
>> 
>> Can't seem to be getting an output.
  <snip>

> Overall I wrote my own version of the code and this is what I got:
>
>
> ******************
> import string
> import random
>
> def random_characters(number):
>     i = 0
>     new_string = []
>
>     while (i < number) :
>         new_string.append(random.choice(string.ascii_lowercase))
>         i = i + 1
>     return "".join(new_string)
>
>
> print(random_characters(3))
> *******

First, I'd clean up the variable name, and use a for loop instead of a
while loop.

import string
import random

def random_characters(number):
    new_list = []
    for i in range(number):
        new_list.append(random.choice(string.ascii_lowercase))
    return "".join(new_list)


print(random_characters(8))

Then I'd probably replace the function body with:

def random_characters(number):
    return "".join([random.choice(string.ascii_lowercase) for i in
range(number)])

-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web