首页 > 解决方案 > 如何要求一个字符串,然后要求一个字符串的位置,然后删除字母并打印没有字母的单词

问题描述

Python

我想创建一个程序,要求用户输入一个字符串,然后要求用户选择要删除的字符串的位置,然后打印没有他选择要删除的位置的字母的字符串。我正在努力寻找正确的方法来做到这一点。

x = input ('Enter a String: ')
sum = 0

if type(x) != str:
    print ('Empty Input')
else:
    y = input ('Enter the position of the string to be removed: ')

for i in range x(start, end):
    print ('New string is: ', x - i)

标签: pythonstring

解决方案


本质上,您如何做到这一点只是使用 .split() 方法通过字符串字母的索引将其拆分,然后使用 join() 方法将其连接起来

x = input ('Enter a String: ')
sum = 0
if type(x) != str:
    print ('Empty Input')
else:
    y = int(input('Enter the position of the string to be removed: '))
x  = ''.join([''.join(x[:y]), ''.join(x[y+1:])])
print(x)


推荐阅读