#Example 1, count all characters in the user's input
fn=input("What is your first name?")
ln=input("What is your surname?")
print("Your first name has " + str(len(fn)) + " characters, and your surname has " + str(len(ln)) + " characters.")
#Example 2, count *only* ASCII letters in user's input
import string
fn=input("What is your first name?")
ln=input("What is your surname?")
fncount=0
lncount=0
for i in fn:
if i in string.ascii_letters:
fncount+=1
for i in ln:
if i in string.ascii_letters:
lncount+=1
print("Your first name has " + str(fncount) + " letters, and your surname has " + str(lncount) + " letters.")
3条答案
按热度按时间vdgimpew1#
print(len(input(“What is your name?“)))
yqkkidmi2#
print(len(input(“What is your name?“)))
pn9klfpd3#
不幸的是,您的代码是在图像中。我使用screen reader,所以看不到图像,但我可以编写一个示例程序: