Quantcast

Jump to content


Photo

Need Quick Python Help


  • Please log in to reply
14 replies to this topic

#1 ~*DK*~

~*DK*~
  • 5 posts

Posted 04 May 2011 - 09:09 AM

done :)
Spoiler

Edited by ~*DK*~, 04 May 2011 - 07:05 PM.


#2 Hydrogen

Hydrogen
  • Neocodex Co-Founder

  • 22213 posts


Users Awards

Posted 04 May 2011 - 09:11 AM

What exactly are you looking for us to help you with? We're not going to do your homework for you :p. At least, I won't :p.

How did you get into this situation anyway?

#3 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 04 May 2011 - 09:12 AM

why don't you summarize things for us so we have a want to help :p Cause ill help in a specific area, but im not going to put much work into it.

#4 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 04 May 2011 - 09:13 AM

Nobody is going to do your homework for you, we're here to help with specific problems.

What exactly are you looking for us to help you with? We're not going to do your homework for you :p. At least, I won't :p.

How did you get into this situation anyway?


why don't you summarize things for us so we have a want to help :p Cause ill help in a specific area, but im not going to put much work into it.


<_<

#5 ilovepolkadots

ilovepolkadots
  • 724 posts

Posted 04 May 2011 - 09:16 AM

What Does Extra Credit Mean?

  • This is not a normal homework, is not required in any way and doing this assignment cannot have any negative impact on your grade.


Edited by ilovepolkadots, 04 May 2011 - 09:17 AM.


#6 ~*DK*~

~*DK*~
  • 5 posts

Posted 04 May 2011 - 09:19 AM

*how i got into this situation:

1. Wrote a 12 page paper on Lenin, Marx, Rousseau, Freud, and Fanon and how they relate to the crisis of modernity
2. did not understand how to do homework 10


for homework 8, we are supposed to add "er" to the end of words, i wrote the best I could, but it seems to add er to the end of the words such as "hi" -> "hiier" and various others :/
source for hw 8:

def add_er(string):
#    if ((string[-1] in ['b','d','g','l','m','n','p','r','s','t']) and\
#        (string[-2:] in ['a','e','i','o','u'])):
#        return(string+'er')
   
    if (string[-1] == 'y'):
        return(string[:-1]+'ier')

    #exceptions to these rules. if the word ends in "eat" then you don't add another consonant
    if (string[-1] == 't' and string[-2] == 'a' and string[-3] == 'e'):
        return(string+'er')
    
    elif (string[-1] == 'e'):
        return(string+'r')

    elif (len(string)<2 or
        (string[-1] in ['b','d','g','l','m','n','p','r','s','t']) or
        (not(string[-3:] in ['a','e','i','o','u']))):
        return(string+string[-1]+'er')
    
    else:
        return(string+'er')

I'll start doing the extra credit in a bit. I guess i'll come back and edit this post with more of my own work :) and ask for help based from there

#7 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 04 May 2011 - 09:48 AM

What would the output you expect to see? because you cannot add er to hi, unless you meant higher... in which case you should be using high and not hi :p More context / examples / experted output would be nice XD

Also :p For your exception in regarding eat.... that is very ugly -.-

if string[-3:] == "eat"


#8 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 04 May 2011 - 10:04 AM

What would the output you expect to see? because you cannot add er to hi, unless you meant higher... in which case you should be using high and not hi :p More context / examples / experted output would be nice XD

Also :p For your exception in regarding eat.... that is very ugly -.-

if string[-3:] == "eat"


Isn't there also an endswith method?

#9 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 04 May 2011 - 10:09 AM

I think so, but the endswith method would call the __getslice__ method, which essentially [start:end]... so this is quicker and more efficient.

Heres a little more help for you ;p

>>> dir("")
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode',
'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex',
'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
'title', 'translate', 'upper', 'zfill']


#10 Hydrogen

Hydrogen
  • Neocodex Co-Founder

  • 22213 posts


Users Awards

Posted 04 May 2011 - 10:27 AM

I think so, but the endswith method would call the __getslice__ method, which essentially [start:end]... so this is quicker and more efficient.

Not really quicker or more efficient. Just makes the code harder to read and maintain.

#11 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 04 May 2011 - 10:33 AM

Not really quicker or more efficient. Just makes the code harder to read and maintain.

Instead of it calling
string -> endswith -> __getsplice__
its going
string -> __getsplice__

and it is much easier to read if you know how to read python properly.

Just another area for us to disagree on eh hydro :p

#12 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 04 May 2011 - 10:49 AM

Instead of it calling
string -> endswith -> __getsplice__
its going
string -> __getsplice__

and it is much easier to read if you know how to read python properly.

Just another area for us to disagree on eh hydro :p


The difference in speed would be minuscule, the benefits of readability would far outweigh that.

#13 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 04 May 2011 - 10:50 AM

The difference in speed would be minuscule, the benefits of readability would far outweigh that.

I agree, but its a good practice to maintain. If he was running through a list of 1million words, it would build up a few seconds over time...

#14 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 04 May 2011 - 10:54 AM

I agree, but its a good practice to maintain. If he was running through a list of 1million words, it would build up a few seconds over time...


But they aren't, so it won't. :p

#15 Hydrogen

Hydrogen
  • Neocodex Co-Founder

  • 22213 posts


Users Awards

Posted 04 May 2011 - 11:58 AM

I agree, but its a good practice to maintain. If he was running through a list of 1million words, it would build up a few seconds over time...

Generally, algorithmic optimization is a much more powerful source of speed improvements than avoiding an extra function call. You should always err on the side of readability. You or someone else will be maintaining the code in the future. Do yourself and others a favor and make it easier on everyone to do their job. Difficult to maintain code is more bug prone. People don't care how fast your program is if it doesn't work properly.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users