CS50P week2 problem set 更新完成

Problem Set 2

Camelcase

image-20240209200307332

image-20240209200319529

注意点:添加 _ 之后,会使得整体列表的数据和索引位置变化

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()

image-20240209200452491

Coke Machine

image-20240210133117581

image-20240210133135950

def main():
    # 总价格
    price = 50
    # 投入的硬币总量
    amount = 0

    # 投入硬币总量不足就一直循环
    while amount < 50
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值