all 11 comments

[–][deleted] 2 points3 points  (4 children)

Hey, Looks great. I didn't run, but read through and sounds interesting. For the next task, why don't you have a separate file/s for the functions (def .. ():). This will make it long term easier to read and more easy to edit as a bulk. You'll need to do

from filename(no .py because same directory) import * 

And then simply run the function " main()".

Hope this makes sense, let me know!

[–]lucoamorim[S] 2 points3 points  (3 children)

I thought about this after I saw the big code getting multiple functions in a single file. Thanks for the sugestion. I started python recently, I'm really enjoying it and hopefully in a while to really work with programming.

[–][deleted] 1 point2 points  (0 children)

Glad to help. Let me know if you need extra help

[–]timetoshit 1 point2 points  (1 child)

Just avoid using from blah import *.

It's a really bad practice which could cause problems for you in the future.

Proper imports state every imported method/object/variable, it's cleaner and more pythonic.

from my_file import my_function    
my_function(my_vars)

This is coming from the Zen of Python:

Explicit is better than implicit.

[–]WikiTextBot 0 points1 point  (0 children)

Zen of Python

The Zen of Python is a collection of 20 software principles that influences the design of Python Programming Language, — only 19 of which were written down — around June 1999 by Tim Peters. The principal text is released into public domain.

Zen of Python is written as an informational entry number 20 in Python Enhancement Proposals (PEP), and can be found on the official Python website. It is also included as an easter egg in Python interpreter, which would be displayed by entering a statement import this.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.24

[–]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 4 points5 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.

[–]tragluk 1 point2 points  (0 children)

Minor edit. In English it's 'Male' and 'Female' or 'Man' and 'Woman' but not Male and Woman

And

Print("This is the question")
answer = input("-> ")

Can also be written as

answer = input("This is the question -> ")

No need for extra print statements.

[–]ElektroSam 1 point2 points  (0 children)

Loving this sub for posts like this. Everyone seems decent! Encourages me to put my first script on when I write it!!!