r/pythontips • • Feb 08 '21

Python3_Specific Morse Code Machine

Hello there! I've started learning python yesterday. I'mm trying to creae a morse code translation. I had some troubles at first, but it looks like that everything is working fine. I would be glad if anyone could gibe me some suggestions. I will look for standars and improove it on the code. I also would like to get some tips on how to abolish the two first options on the menu and create a function that can automatically detect if the user inserted an alphabetic text or a morse coee one.

Git Hub link: https://gist.github.com/VitorGRM/7c5165831224bcadb6c76f06c1fdaccb

29 Upvotes

3 comments sorted by

2

u/blowingmindssince93 Feb 08 '21 edited Feb 08 '21

Hi! Nice job it does what it needs to and for someone who started yesterday it's looking good! I'm sure there's other people with more experience that will weigh in on some of the standards etc I was just going to make a suggestion for your point about automatically identifying if it is more code or words, python has isalpha() which checks if the thing inside it is an alphabetic character I'd think an easy way to achieve what you want would be something like

If isalpha(input_phrase) :

    Print(Codify(input_phrase))

Else:

    Print(decodify(input_phrase))

1

u/[deleted] Feb 08 '21

Thanks a lot! Python features so many methods and such that makes things so easier. I lost so much time trying to create a function that checks the alphabet with if statements and loops (as I’d have to do in c++). I’ll definitively use this .isalpha(). Thanks. Is there any documentation page that deals only with this kind of method?

2

u/blowingmindssince93 Feb 08 '21

I can imagine! I still do the same sometimes to be honest I think it's natural when you're starting out and I'm still new to it all as well! I've just found this page: https://docs.python.org/3/library/stdtypes.html that covers a tonne of the built in types, boolean functions and data type testing are all covered in it