Python Problem [Solved ✅] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python Problem [Solved ✅]

I wrote a code that determines if the user wrote something or not using none, but when I typed nothing, it said that I wrote something. https://code.sololearn.com/c9DCc65MO06Z/#py

23rd Nov 2020, 1:14 AM
:DD
:DD - avatar
2 Answers
+ 2
Inputting nothing does not means that the value of input is none. You can use the length of input. user = input() if len(user)==0: print("Bruh, you wrote nothing! XDDDDDDDDDDDDD") else: print("OOH~! THANK GOODNESS! YOU WROTE SOMETHING!")
23rd Nov 2020, 1:46 AM
Deep Kr. Ghosh
Deep Kr. Ghosh - avatar
+ 1
input() will return an empty string ('') if nothing is entered. '' is not equal to None. It is however a falsy value, so, you can just say; if user: # else block runs Or if not user: # if block runs instead of; if user is None: Or if user == None: https://www.google.com/amp/s/www.geeksforgeeks.org/truthy-vs-falsy-values-in-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/
23rd Nov 2020, 1:41 AM
ChaoticDawg
ChaoticDawg - avatar