Python&字符串/循环帮助请

时间:2015-05-18 01:06:00

标签: python

我正在试图弄清楚如何输入输入的名称:

<class name = "A">
  <subselect> select ... from VIEW</subselect> 
    <component name = "b">
     <bag name ="list" lazy="false" cascade = "all">
      ....
    </bag>
   </component>
</class>

通过使用while循环将其更改为完全向后。

例如:将full_name = input('Enter your full name ') 设为Jenny King

提前致谢:)

1 个答案:

答案 0 :(得分:0)

1-使用while循环

i = len(full_name.split()) - 1
while(i >= 0):
    print full_name.split()[i]
    i = i-1

2-切片

x = full_name.index(" ")
new_string = full_name[x+1:] + " " + full_name[0:x]
print new_string

3-计算下部和上部

lower = 0
upper = 0
for letter in full_name:
    if letter.islower():
        lower = lower + 1
    elif letter.isupper():
        upper = upper + 1
print "number of lower letters = %s" % lower 
print "number of upper letters = %s" % upper 

4-纠正句子

bad_string = "You have to be vewy, vewy twicky to twap a wascally wabbit"
correct_string = bad_string.replace('w', 'r')
print correct_string