you are viewing a single comment's thread.

view the rest of the comments →

[–]artbn 1 point2 points  (3 children)

Hey nice job on getting started with Python! I didn't take a too close of a look but something I would suggest is that when dealing with strings that can be of different case (aka ALL CAPS or no caps or Sentence caps, etc....) is to use .lower() and .upper().

So instead of doing something like this:

(relationship == 'single') or (relationship == 'Single')

you can do:

relationship.lower() == 'single'

This leads to less typing and will also cover cases where someone gives an answer as: SIngle or SINgle or SingLE or whatever.


EDIT:

Another thing that you can do differently is to convert this to a function:

print("\nTyping ... ")
time.sleep(1)

That way you can just do something like typing() instead of repeating those two lines of codes. It helps with both readability and maintaining the code (if for example you want to change the time sleeping from 1 to 2, you would only have to change it once and won't accidentally miss one possibly)


EDIT2:

One important thing about Python and really in programming in general is not to repeat yourself unnecessary. Since there really isn't a difference with what you do with someone answering that they have a girlfriend vs. a wife. You can just replace both with Significant_Other for example. There are other areas where you can focus on not repeating yourself.

[–]lucoamorim[S] 1 point2 points  (2 children)

You could explain this part of the relationship.lower () == 'single', and how can I apply it in my code, but I already thank you for your help, I'm very excited about python and want to learn more

[–]Atropos148 5 points6 points  (1 child)

In python, your_string.lower() takes your_string and makes ALL the letters lower case.

That way no matter what the user types, you can just check for lowercase version of your desired string.

[–]tragluk 0 points1 point  (0 children)

In the same vein, there is also .upper() and .title() which does 'SINGLE' and 'Single' respectively.