编写程序(需使用循环结构),程序运行后,输入python,输出结果入下图: ppppppppppp yyyyyyyyy ttttttt hhhhh ooo n
时间: 2024-02-10 10:54:39 浏览: 64
python程序input函数的输出
word = input("请输入一个单词:") # 获取输入的单词
for i in range(len(word)): # 循环遍历单词的每个字符
if word[i] == "p": # 如果是字母p,输出12个p
print("p", end="")
for j in range(11):
print("p", end="")
elif word[i] == "y": # 如果是字母y,输出9个y
print("y", end="")
for j in range(8):
print("y", end="")
elif word[i] == "t": # 如果是字母t,输出7个t
print("t", end="")
for j in range(6):
print("t", end="")
elif word[i] == "h": # 如果是字母h,输出5个h
print("h", end="")
for j in range(4):
print("h", end="")
elif word[i] == "o": # 如果是字母o,输出3个o
print("o", end="")
for j in range(2):
print("o", end="")
elif word[i] == "n": # 如果是字母n,输出1个n
print("n", end="")
print() # 输出换行符,使结果在一行显示
阅读全文