查看: 331|回复: 0

星际跳高

[复制链接]

237

主题

314

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
21620
发表于 2022-7-12 00:44:07 | 显示全部楼层 |阅读模式
1.当没有return时,代码会返回None

2.月球跳跃高度
def jump(height):
    result = height*6
    print(result)
  jump(1)

3.半成品代码
def jump(height, planet):
    if planet == '月球':
        result = height*6
    if planet == '火星':
        result = height*2.5
    if planet == '木星':
        result = height*0.4
    print(result)                 
  jump(1,'火星')

4.完整代码
def jump(height, planet):
    if planet == '月球':
        result = height*6
    if planet == '火星':
        result = height*2.5
    if planet == '木星':
        result = height*0.4
    sentence = '你可以在' + planet + '跳' + str(result) + '米'
    print(sentence)

    print(f'你可以在{planet}跳{result}米')
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表