r/PythonLearning • • Aug 24 '25

My first code

Post image

First time coding
any ideias or ways to improve it?

76 Upvotes

21 comments sorted by

2

u/ProminenceBow Aug 24 '25

Dá pra você simplificar algumas linhas, como as 4 primeiras linhas apenas em:

usuário = input("Bem-vindo ao sistema de login!/nDigite aqui o seu usuário:")

(Você coloca os símbolos também, mas não quis contar)

O /n dentro de uma string serve para você fazer uma quebra de linha, então com ele você não precisa fazer vários prints.

Com o método input você pode colocar uma string que você queira que apareça antes do input, então dá pra você simplificar bastante coisa aí

1

u/JournalistHot3749 Sep 03 '25

Anotado man! eu n sabia disso, vou começar a usar sempre agora
vlw! :)

1

u/[deleted] Aug 24 '25

[removed] — view removed comment

2

u/ProminenceBow Aug 24 '25

Isso, tô no celular e nem percebi kkkkkkk

2

u/Far_Departure_1580 Aug 24 '25

Eai brasileiro! How are you?

2

u/JournalistHot3749 Aug 24 '25

Salve man kkkkk

6

u/Specialist_Set1921 Aug 24 '25

I would avoid any special characters in the code. Especially in the variable names and filenames. Eg â or à

Just to prevent any possible headaches.

1

u/shudaoxin Aug 25 '25

Except for strings shown to the user I’d use English for variables, functions, objects etc. Not only is it easier to understand the flow (because the Python itself uses English), but it’s also easier for someone else to understand and help you, generally.

Using non English characters in variables or code related bits like you did with usuário here is an absolute crime though. It works in a lot of programming languages but is really bad practice.

I don’t mean to discourage or discredit your work here. Just some feedback to avoid bad habits early on. Keep on learning!

1

u/JournalistHot3749 Sep 03 '25

Chill bro! a little after I posted this code I watched a couple of videos of good habits to write and this was the top 1
I re-wrote the whole code as soon as I realized the potential problems that writing like this could have!

ty for your feedback! (btw, feel free to see the newest version to check out the evolution 🙂 )

1

u/[deleted] Aug 24 '25

If you are using \ in your strings, just use \ to prevent Python from seeing it as a special code/character

Looks good. Well done.

1

u/CraigAT Aug 24 '25

I don't think you want to "while" statements at the bottom. Instead you may want a while loop around the login process so you can repeat it again if the wrong details are entered. You may also want to count the number of wrong attempts and stop or lock out the user.

1

u/Some-Passenger4219 Aug 25 '25

Nothing is changed in those while loops. Therefore, they either run forever or do nothing. Remember, a while loop does the statement(s) over and over until the condition is no longer met. Kinda like that "Flo in the button factory" song.

1

u/tortleme Aug 25 '25

nice infinite loop x 2

0

u/JournalistHot3749 Aug 24 '25

Just made some optimizations!, any thoughts?
btw, thank you for the feedback <3

1

u/IntelligentCattle653 Aug 27 '25

no need login() == True, by default is True

1

u/spp649 Aug 24 '25

well it will play login 3 times so make a variable then check if its true or not.

1

u/spp649 Aug 24 '25

also i forgot to mention but \ is used for escape sequences so use \ for a \

1

u/spp649 Aug 24 '25

you can do something like

#... your code while login() != true: # ... your code

so if its not true it does whats in the while loop then if its true it continues

0

u/gigsoll Aug 24 '25

You need to use English variables names, except this – decent code

1

u/[deleted] Aug 25 '25

[removed] — view removed comment

1

u/JournalistHot3749 Sep 03 '25

yeah, eventually I re-wrote the whole code fixing this!
thank god someone said this to me before things got crazy 😅