Problem Set 2
Camelcase


注意点:添加 _ 之后,会使得整体列表的数据和索引位置变化
def main():
camelcase = list(input("camelcase: "))
snakecase = change_to_snake_case(camelcase)
print(snakecase)
def change_to_snake_case(list_camel):
length = len(list_camel)
# 用于记录大写字母的位置
tmp = []
# 循环找出大写字母,并将大写字母转化成小写字母
# 记录下大写字母的位置,方便后续添加
for i in range(length):
if list_camel[i].isupper():
tmp.append(i)
list_camel[i] = list_camel[i].lower()
# 添加函数
add(tmp, list_camel)
return "".join(list_camel)
def add(list_tmp, list_camel):
# 用于记录前面添加了几个,添加几个后面的需要整体往后移动
count = 0
for index in list_tmp:
list_camel.insert(index + count, "_")
count += 1
return list_camel
if __name__ == '__main__':
main()

Coke Machine


def main():
# 总价格
price = 50
# 投入的硬币总量
amount = 0
# 投入硬币总量不足就一直循环
while amount < 50


被折叠的 条评论
为什么被折叠?



