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

30th Jun 2017, 1:45 AM
Mohamed Mohamedy
Mohamed Mohamedy - avatar
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.
1st Jul 2017, 6:50 AM
David Ashton
David Ashton - avatar
+ 5
>tfw I do both bad practices in your code can you explain what's bad about them, and how to do them better?
30th Jun 2017, 11:22 AM
Ahri Fox
Ahri Fox - avatar
+ 4
dont worry, if it works its not stupid
30th Jun 2017, 2:00 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 4
What do you mean about the 'bad practices'?
30th Jun 2017, 2:04 AM
DeltaTick
DeltaTick - avatar
+ 3
idk lol even sl claims that no semicolons on javascript is "bad practice" is ok if it works just go on
30th Jun 2017, 2:12 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 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.
30th Jun 2017, 11:56 AM
Daen Rowe
Daen Rowe - avatar
+ 2
@Daen Rowe i know which statement ends because i use newline bruh i dont write my codes in one line
30th Jun 2017, 12:00 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 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.
30th Jun 2017, 11:47 AM
Mohamed Mohamedy
Mohamed Mohamedy - avatar
+ 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"
30th Jun 2017, 11:58 AM
Daen Rowe
Daen Rowe - avatar
+ 1
im on web and that code doesnt even have the bad practices warning
30th Jun 2017, 12:03 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
@David, amazing! that's what im talking about. I totally forgot to test upper cases too. 😌
1st Jul 2017, 7:22 PM
Mohamed Mohamedy
Mohamed Mohamedy - avatar
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 ..
30th Jun 2017, 8:18 AM
Mohamed Mohamedy
Mohamed Mohamedy - avatar
0
oh, im sorry that you depend on ide-based development! :D
30th Jun 2017, 12:24 PM
Mohamed Mohamedy
Mohamed Mohamedy - avatar