![]() |
|
[Python] No content, no purpose - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] No content, no purpose (/showthread.php?tid=6169419) |
No content, no purpose - david0369 - Aug 23, 2021 Code # I have been learning python for 3 daysRE: No content, no purpose - 3phase - Aug 23, 2021 When you paste code here, use "code" tags around the code, so we can get the indentation of your code ( which is very important in python..). Now let's dive in 🕵️ First of all, use more meaningful names for your parameters, and try to avoid numbers in them. for example Code un1 = input('Registered account name: ')For the While loop you don't need data1, because you are using break at the end, which make data1 to be uselss, you don't need an actual parameter to make a boolean equation Code data1 = FalseWhen you ask for input from the user, make sure you mention all the rules, you cant just ask for a password with no further information Code up1 = input('Register account password: ')and then "punish" the user for not making it 6 digits password Code if len(up1) != 6:The flow logic based on incremented "error" counter, is kinda mess you don't need it as you can see, the code looks pretty complicated for a very simple task. You can just use While True and break it whenever you need to "ensure" stuff before the next stage. On the last line of your function you make Code data = print('account number:{0}\npassword:{1}\nPlease save the account password and other information'.format(un1, up2))Code somthing = print(...)also use f-string, its much better than format, its more efficient and readable its looks like that, Code print(f'account number:{un1}\n'Here is my version for your code, nothing fancy but you can tell its much cleaner and understanable Code def Application_1():Hope you learned something from that, practice makes perfect, good luck! RE: No content, no purpose - czarnylab - Aug 30, 2021 Code Application_1()make it into Code if __name__ == '__main__':This is a community standard for running python scripts. So then you can use your function like this: Code python myscript.pyYou are doing great, keep going! RE: No content, no purpose - david0369 - Aug 30, 2021 (Aug 30, 2021 11:45 AM)czarnylab Wrote: thanks so much |