我在尝试执行此代码时遇到问题,我希望用户输入一个值,程序检查该值是否为字符串,然后返回长度。如果该值包含空格,则程序会删除空格并打印长度。但如果它包含任何整数值,程序将返回“不允许整数”
这是代码:
def length(Name):
long = len(Name)
return long
new_length = input("Please Enter Your name You can use Spaces: ")
value1 = new_length
if value1.isspace() == True:
print("This is Before Removing Spaces: " + value1)
value2 = value1.replace(" ", "")
print("This is After Removing Spaces: " + value2)
elif value1.isalpha() == True:
print("Here is The Length: ", length(value1))
elif value1.isdigit() == True:
print("Integers are not allowed! ")
else:
print("There's someting wrong with "+ value1)
因此,如果您能帮助我,我将不胜感激。 谢谢