欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

【Python CheckiO 题解】Say Hi

发布时间:2023/12/10 python 42 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【Python CheckiO 题解】Say Hi 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

CheckiO 是面向初学者和高级程序员的编码游戏,使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务,从而提高你的编码技能,本博客主要记录自己用 Python 在闯关时的做题思路和实现代码,同时也学习学习其他大神写的代码。

CheckiO 官网:https://checkio.org/

我的 CheckiO 主页:https://py.checkio.org/user/TRHX/

CheckiO 题解系列专栏:https://itrhx.blog.csdn.net/category_9536424.html

CheckiO 所有题解源代码:https://github.com/TRHX/Python-CheckiO-Exercise


题目描述

【Say Hi】:你的任务是编写一个根据给出的属性参数来介绍一个人的函数

【链接】:https://py.checkio.org/mission/say-history/

【输入】:两个参数,一个字符串(str)和一个正整数(int)

【输出】:字符串(str)

【范例】

say_hi("Alex", 32) == "Hi. My name is Alex and I'm 32 years old" say_hi("Frank", 68) == "Hi. My name is Frank and I'm 68 years old"

代码实现

# 1. on CheckiO your solution should be a function # 2. the function should return the right answer, not print it.def say_hi(name: str, age: int) -> str:return "Hi. My name is " + name + " and I'm " + str(age) + " years old"if __name__ == '__main__':#These "asserts" using only for self-checking and not necessary for auto-testingassert say_hi("Alex", 32) == "Hi. My name is Alex and I'm 32 years old", "First"assert say_hi("Frank", 68) == "Hi. My name is Frank and I'm 68 years old", "Second"print('Done. Time to Check.')

大神解答

大神解答 NO.1

def say_hi(name: str, age: int) -> str:return f"Hi. My name is {name} and I'm {age} years old"

大神解答 NO.2

def say_hi(name: str, age: int) -> str:return "Hi. My name is {0} and I'm {1} years old".format(name, age)

总结

以上是生活随笔为你收集整理的【Python CheckiO 题解】Say Hi的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。