Write a program that reads in a string and prints whether it contains only letters contains only uppercase letters contains only lowercase letters contains only digits contains only letters and digit
string = input("Enter a string: ")
if string.isalpha(): print("The string contains only letters.") elif string.isupper(): print("The string contains only uppercase letters.") elif string.islower(): print("The string contains only lowercase letters.") elif string.isdigit(): print("The string contains only digits.") elif string.isalnum(): print("The string contains only letters and digits.") else: print("The string contains other characters.")
if string[0].isupper(): print("The string starts with an uppercase letter.") else: print("The string does not start with an uppercase letter.")
if string.endswith("."): print("The string ends with a period.") else: print("The string does not end with a period.")
原文地址: http://www.cveoy.top/t/topic/boTr 著作权归作者所有。请勿转载和采集!