1.
Write an if statement that verifies that the string has characters.
You’ll want to run your code multiple times, testing an empty string and a string with characters. When you’re confident your code works, continue to the next exercise.
Program:
#Take user input
userString = input("Enter a word: ")
#Calculate lenght of string
length = len(userString)
#Check whether length is greater than zero and string has
charcters
if length>0 and userString.isalpha():
print(userString)
else:
print("empty")
Screenshot for proper indentation:
Output;
Get Answers For Free
Most questions answered within 1 hours.