- Joined
- Jul 4, 2023
- Messages
- 507
- Reaction score
- 63
Like in title ...
One of the comments on the Python video made me laugh out loud.
Here is code from movie
another version of the code shown above, proposed by the author of the video
other proposed code version
One of the comments on the Python video made me laugh out loud.
Here is code from movie
Python:
user_input = input('Name: ')
if user_input:
name = user_input
else:
name = 'N/A'
print(name)
another version of the code shown above, proposed by the author of the video
Python:
user_input = input('Name: ')
name = user_input or 'N/A'
print(name)
other proposed code version
Python:
name = input('Name: ') or 'N/A'
print(name)
user_input = input('Name: ')
name = user_input if user_input else 'N/A'
print(name)
print(input('Name: ') or 'N/A')
# remove white space
name = input('Name: ').strip() or 'N/A'
print(name)
print(name:=input('Name: ') or 'N/A')
# and now you can use the "name" variable too
# My code suggestion
import re
# remove white space and the name must be longer than 2 characters
name = re.sub(r'^.{1,2}$', '', input('Name: ').strip()).strip() or 'N/A'
print(name)
Last edited: