人工智能与python学习速查

kaggle学习教程

备注

尽量看英语,不认识的就大概猜一下什么意思。

遗忘速查:(一些经常记不住的东西)

# string
len(str) # string的长度

基础

Conditions and Conditional Statements

准备工作:

from learntools.core import binder
binder.bind(globals())
from learntools.intro_to_programming.ex4 import *
print('Setup complete.')

Question 1 if else

You work at a college admissions office. When inspecting a dataset of college applicants, you notice that some students have represented their grades with letters ("A""B""C""D""F"), whereas others have represented their grades with a number between 0 and 100.

You realize that for consistency, all of the grades should be formatted in the same way, and you decide to format them all as letters. For the conversion, you decide to assign:

  • "A" - any grade 90-100, inclusive
  • "B" - any grade 80-89, inclusive
  • "C" - any grade 70-79, inclusive
  • "D" - any grade 60-69, inclusive
  • "F" - any grade <60

Write a function get_grade() that takes as input:

  • score - an integer 0-100 corresponding to a numerical grade

It should return a Python string with the letter grade that it corresponds to. For instance,

  • A score of 85 corresponds to a B grade. In other words, get_grade(85) should return "B".
  • A score of 49 corresponds to an F grade. In other words, get_grade(49) should return "F".

Make sure that when supplying the grade that is returned by the function, it is enclosed in quotes. (For instance, if you want to return "A", you should write return "A" and not return A.)

def get_grade(score):
    if 90<=score:  grade = "A" 
    elif 80<=score: grade = "B" 
    elif 70<=score:  grade = "C" 
    elif 60<=score:  grade = "D" 
    else: grade = "F" 
    return grade

 这个问题比较简单,定义函数,简单的逻辑判断就可以完成。

Question 2

In the exercise for the previous lesson, you wrote a function cost_of_project() that estimated the price of rings for an online shop that sells rings with custom engravings. This function did not use conditional statements. In this exercise, you will rewrite the function to use conditional statements. Recall that the online shop has the following price structure:

  • Gold plated rings have a base cost of $50, and you charge $7 per engraved unit.
  • Solid gold rings have a base cost of $100, and you charge $10 per engraved unit.
  • Spaces and punctuation are counted as engraved units.

Your function cost_of_project() takes two arguments:

  • engraving - a Python string with the text of the engraving
  • solid_gold - a Boolean that indicates whether the ring is solid gold

It should return the cost of the project.

The function has been partially completed for you, and you need to fill in the blanks to complete the function.

def cost_of_project(engraving, solid_gold):
    if solid_gold == True:
        cost = 100 + len(engraving) * 10
    else:
        cost = 50 + len(engraving) * 7
    return cost

 python中string长度函数,len(str)。

  • 16
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 要下载Python3自学手册,可以按照以下步骤进行操作: 1. 打开浏览器,在搜索引擎中输入"Python3自学手册下载",点击搜索按钮。 2. 在搜索结果中,找到可信赖的网站或资源,比如Python官方网站、开源项目网站或者编程社区。确保选择的来源具有正版的手册资源。 3. 进入所选网站,找到Python3自学手册的下载页面。 4. 在下载页面中,找手册的下载链接或按钮,通常是以"下载"或"Download"的形式显示。点击该链接或按钮。 5. 确认下载选项,如手册的版本、格式等。选择合适的下载选项,点击下载按钮。 6. 等待一段时间,直到手册的下载任务完成。下载过程中,可以看下载进度,确定时间的长短取决于下载度和手册的大小。 7. 下载完成后,找到下载的文件。通常会在计算机的"下载"文件夹中,或者浏览器的下载历史中看到。手册可能是一个PDF文件、电子书格式或网页文档。 8. 打开下载的手册文件,开始自学学习Python3的内容。 总结来说,下载Python3自学手册需要在可信赖的网站上找到手册的下载页面,选择合适的下载选项并等待下载完成。下载完成后,打开手册文件即可开始学习Python3。 ### 回答2: 要下载Python 3自学手册,您可以按照以下步骤进行操作。 1. 打开您的网页浏览器并进入Python官方网站(https://www.python.org)。 2. 在页面顶部的菜单中找到“Downloads”(下载)选项并点击它。 3. 在下载页面上,您会看到Python的最新版本,向下滚动找到适用于您的操作系统的版本。例如,如果您使用的是Windows操作系统,您可以点击“Windows”链接。 4. 在Windows下载页面上,您会看到多个可供选择的版本,包括32位和64位版本。根据您的操作系统类型(32位或64位)选择适当的版本,并点击链接开始下载。 5. 下载过程可能需要一些时间,具体时间取决于您的网络度。 6. 下载完成后,找到下载的安装程序并双击运行它。 7. 跟随安装程序的指示完成Python 3的安装过程。 8. 安装完成后,您可以在开始菜单或应用程序列表中找到Python 3的安装文件夹,并找到手册或文档。 下载Python 3自学手册后,您可以通过阅读手册中的内容来快了解Python 3的语法、函数和常用模块等。这个手册可以帮助您快掌握Python编程基础,并作为学习和参考的便捷工具。 ### 回答3: 要下载Python3的自学手册,可以按照以下步骤进行操作: 1. 打开浏览器,并访问Python官方网站(https://www.python.org)。 2. 在页面的顶部菜单中,点击"Downloads"(下载)。 3. 在下载页面中,向下滚动,找到"Latest Python 3 Release - Python 3.x.x"(最新Python 3版本)的部分。 4. 在该部分中,选择适合你操作系统的下载链接。例如,如果你使用的是Windows系统,可以点击"Windows x86-64 executable installer"(Windows 64位可执行安装程序)。 5. 点击下载链接后,会自动下载Python3安装程序的可执行文件(例如,.exe文件)。 6. 打开下载完成的文件,按照安装向导的指示进行安装。在安装过程中,可以选择是否添加Python到系统的环境变量中。 7. 完成安装后,会在系统中创建一个Python3的可执行文件,可以在命令行或终端中通过输入"python"或"python3"来启动Python解释器。 8. 为了获取自学手册,可以通过搜索引擎在互联网上找到相关资源。有很多网站和博客提供免费在线阅读或下载的Python3手册。 9. 选择一个信任的网站,下载适合自己的Python3手册。通常,手册的格式为PDF或网页。 10. 下载完成后,通过文件管理器打开手册,即可开始学习Python3的相关知识。 以上就是下载Python3自学手册的步骤。祝你学习Python的过程顺利并取得好成果!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值