码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 语法练习:not_string


    语法练习:not_string

    题目:not_string

    Given a string, return a new string where "not " has been added to the front. However, if the string already begins with “not”, return the string unchanged.

    not_string(‘candy’) → ‘not candy’
    not_string(‘x’) → ‘not x’
    not_string(‘not bad’) → ‘not bad’

    我的解答:

    def not_string(str):
      if str[:3] == "not":
        return str
      else:
        return "not " + str
    
    • 1
    • 2
    • 3
    • 4
    • 5

    Expected Run
    not_string(‘candy’) → ‘not candy’ ‘not candy’ OK
    not_string(‘x’) → ‘not x’ ‘not x’ OK
    not_string(‘not bad’) → ‘not bad’ ‘not bad’ OK
    not_string(‘bad’) → ‘not bad’ ‘not bad’ OK
    not_string(‘not’) → ‘not’ ‘not’ OK
    not_string(‘is not’) → ‘not is not’ ‘not is not’ OK
    not_string(‘no’) → ‘not no’ ‘not no’ OK

    All Correct

    标答:

    def not_string(str):
      if len(str) >= 3 and str[:3] == "not":
        return str
      return "not " + str
      # str[:3] goes from the start of the string up to but not
      # including index 3
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    洛谷刷题C语言:远古档案馆(Ancient Archive)、VOLIM、SAHOVNICA、Tuna、KRIŽALJKA
    QT6 C++获取Linux系统计算机的主机BIOS序列号源代码
    史上最全的Redis基础+进阶项目实战总结笔记
    【图灵MySQL】深入理解Mysql索引底层数据结构与算法
    使用融云 CallPlus SDK,一小时实现一款 1V1 视频应用
    Java/ExecutorService中多线程服务ExecuteService的使用
    HashMap面试原理梳理-简单一看就懂
    建模助手(Revit)插件如何生成基坑开挖和地下连续墙?
    如何将base64图片转化为URL格式
    Rust学习日记(二)变量的使用--结合--温度换算/斐波那契数列--实例
  • 原文地址:https://blog.csdn.net/sunbocong/article/details/128205870
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号