0
I did something wrong, help me fix it!
I just wrote my first code snippet and published it here, it contains two bad practices I marked them. can you figure out what they are, and what to use instead? here's a link: https://code.sololearn.com/cMmIIF9KR74s/?ref=app
13 RĂ©ponses
+ 7
How about this?
text = input('Enter your text: ')
vowels = 'aeiouAEIOU'
found = sum(text.count(x) for x in vowels)
print('There are {} vowels in \'{}\'.'.format(found, text))
# print(f'There are {found} vowels in \'{text}\'.')
# works in Python 3.6 but not in SL yet.
+ 5
>tfw I do both bad practices in your code
can you explain what's bad about them, and how to do them better?
+ 4
dont worry, if it works its not stupid
+ 4
What do you mean about the 'bad practices'?
+ 3
idk lol even sl claims that no semicolons on javascript is "bad practice" is ok if it works just go on
+ 2
@cheeze of course leaving semicolons out at the end of statements if it works who cares right?
wrong depending on your style of writing it can be a huge mess because it will be extremely hard to remember where a statement ends. semicolon helps with that.
+ 2
@Daen Rowe i know which statement ends because i use newline bruh i dont write my codes in one line
+ 1
@ahri fox
both string concatenation and formatting here are the "c way".
the c way concatenation is not recommended in pep8, because:
- it doesn't work with all types
- it's not consistent with other python implementation -ironpthon, jpython ..etc
so, it's better to use the .join() method instead.
starting from python 3.x, the old c-style string formatting - "hello, %s" %"world "-
is replaced with the new .format() method.
+ 1
i assumption is that there is a better and more cleaner method of using in each statment .. but idk python at all to know what are "best practices"
+ 1
im on web and that code doesnt even have the bad practices warning
+ 1
@David, amazing! that's what im talking about. I totally forgot to test upper cases too. đ
0
nah, you didn't get it guys! you should figure out how this code could be improved!
it's like a tutorial about bad practices or do's and donts in python ..
0
oh, im sorry that you depend on ide-based development! :D