Quiz 4: Functions | Python for Everybody 配套练习_解题记录

news2024/10/5 21:21:03

文章目录

  • 课程简介
      • Quiz 4: Functions
    • 单选题(1-9)
    • 编程题
      • Exercise 4.6


课程简介

Python for Everybody 零基础程序设计(Python 入门)

  • This course aims to teach everyone the basics of programming computers using Python. 本课程旨在向所有人传授使用 Python 进行计算机编程的基础知识。
  • We cover the basics of how one constructs a program from a series of simple instructions in Python. 我们介绍了如何通过 Python 中的一系列简单指令构建程序的基础知识。
  • The course has no pre-requisites and avoids all but the simplest mathematics. Anyone with moderate computer experience should be able to master the materials in this course. 该课程没有任何先决条件,除了最简单的数学之外,避免了所有内容。任何具有中等计算机经验的人都应该能够掌握本课程中的材料。
  • This course will cover Chapters 1-5 of the textbook “Python for Everybody”. Once a student completes this course, they will be ready to take more advanced programming courses. 本课程将涵盖《Python for Everyday》教科书的第 1-5 章。学生完成本课程后,他们将准备好学习更高级的编程课程。
  • This course covers Python 3.

在这里插入图片描述

coursera

Python for Everybody 零基础程序设计(Python 入门)

Charles Russell Severance
Clinical Professor

在这里插入图片描述

个人主页
Twitter

在这里插入图片描述

University of Michigan


课程资源

coursera原版课程-外网
coursera原版视频-中英文精校字幕-B站
Dr. Chuck官方翻录版视频-机器翻译字幕-B站

PY4E-课程配套练习-部分功能需科学上网
Dr. Chuck Online - 系列课程开源官网


Quiz 4: Functions

Take a brief look at how Python implements the ‘store and use later’ programming pattern.



单选题(1-9)

  1. Which Python keyword indicates the start of a function definition?
  • sweet
  • def
  • break
  • help
  1. In Python, how do you indicate the end of the block of code that makes up the function?
  • You de-indent a line of code to the same indent level as the def keyword
  • You add the matching curly brace that was used to start the function
  • You put a
  • You put the “END” keyword in column 7 of the line which is to be the last line of the function
  1. In Python what is the input() feature best described as?
  • A built-in function
  • A conditional statement
  • A user-defined function
  • The central processing unit
  1. What does the following code print out?
def thing():
    print('Hello')
 
print('There')
  • Hello
  • defthing
  • There
  • thingHelloThere
  1. In the following Python code, which of the following is an “argument” to a function?
x = 'banana'
y = max(x)
print(y)
  • x
  • max
  • print
  • ‘banana’
  1. What will the following Python code print out?
def func(x) :
    print(x)
 
func(10)
func(20)
  • 1020
  • x10x20
  • x20
  • funcfunc
  1. Which line of the following Python program will never execute?
def stuff():
    print('Hello')
    return
    print('World')
 
stuff()
  • def stuff():
  • stuff()
  • return
  • print (‘World’)
  • print(‘Hello’)
  1. What will the following Python program print out?
def greet(lang):
    if lang == 'es':
        return 'Hola'
    elif lang == 'fr':
        return 'Bonjour'
    else:
        return 'Hello'
 
print(greet('fr'),'Michael')
  • HolaBonjourHelloMichael
  • defHolaBonjourHelloMichael
  • Bonjour Michael
  • Hola Michael
  1. What is the most important benefit of writing your own functions?
  • To avoid having more than 10 lines of sequential code without an indent or de-indent
  • Avoiding writing the same non-trivial code more than once in your program
  • Following the rule that whenever a program is more than 10 lines you must use a function
  • Following the rule that no function can have more than 10 statements in it

编程题

Exercise 4.6

题目:
Write a program to prompt the user for hours and rate per hour using input to compute gross pay.
Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours.
Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value.
Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number.
Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.

[Desired Output]
Pay 498.75

解题代码:

def computepay(hours, rate):
   if h <= 40:
       per = h * r
   else:
       per = 40 * r + (h - 40) * r * 1.5
   return per

hrs = input("Enter Hours:")
rat = input("Enter Hourly rate:")
h = float(hrs)
r = float(rat)

p = computepay(h, r)
print("Pay", p)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/704764.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JAVA2

文章目录 前言 前言 创建&#xff0c;编译java&#xff08;每4修改一次就要重新编译&#xff01;&#xff09; 第一个程序&#xff1a; 解决中文乱码问题&#xff1a; 效果&#xff1a; 总结&#xff1a;

管理类联考——英语——趣味篇——词根词汇——按频次分类——高频词汇——List1

优化原书记忆方法&#xff0c;轻松搞定考研单词 摒弃了传统的以字母顺序排序的方法&#xff0c;结合近20年考研真题&#xff0c;通过电脑搜索等方法对核心词进行科学统计&#xff0c;将核心词有机地分为高频词汇、常考词汇、中频词汇、低频词汇等4大部分&#xff0c;同时还补充…

一个三极管和稳压管构成的简易稳压电源

一个三极管和稳压管构成的简易稳压电源 先看电路 原理分析&#xff1a; 实际使用中可以加入合适的滤波电容。 上面的电路原理看着比较简单&#xff0c;但还是有不少要注意的地方。 来看看仿真电路的结果&#xff1a; 可以看到&#xff0c;输出的电压并不是我们想要的结果&am…

高压线路距离保护程序逻辑原理(五)

六、系统振荡的判断与振荡闭锁程序逻辑框图 &#xff08;一&#xff09;系统振荡概述 电力系统的振荡大致可以分为两种情况&#xff1a;一种是静稳破坏引起系统振荡&#xff0c;另一种是由于系统内故障切除时间过长&#xff0c;导致系统的两侧电源之间的不同步而引起的系统振…

【单片机】MSP430单片机,1.3寸 IIC OLED ,显示驱动

文章目录 main.coled.holedfont.h main.c #include <msp430.h> #include "OLED.h"int main( void ) {WDTCTL WDTPW WDTHOLD; /* Stop WDT */if ( CALBC1_8MHZ 0xFF ) /* If calibration constant erased */{while ( 1 ); /* do n…

C++ DAY4

1.思维导图 2.运算符重载 #include <iostream> using namespace std;class Person { private:int age;int *p; public://1.无参构造Person():p(new int(89)){age 18;}//2.有参构造Person(int age,int num){this->age age;this->pnew int(num);}//3.拷贝构造函数…

数据库中的日期函数DM和mysql都通用,计算年月日时分秒,获取日期之间相差的值

select MINUTE(date) from t_test; year month day hour minute second --对应年月日时分秒 select date from t_test select MINUTE(createtime),to_char(sysdate(),yyyy-MM-dd) select TIMESTAMPDIFF(minute,date,now()),date from t_test DateUtil.between(new Date(),ne…

小程序底层技术机制解读:版本更新与底层运行原理

&#x1f482; 个人网站:【海拥】【游戏大全】【神级源码资源网】&#x1f91f; 前端学习课程&#xff1a;&#x1f449;【28个案例趣学前端】【400个JS面试题】&#x1f485; 寻找学习交流、摸鱼划水的小伙伴&#xff0c;请点击【摸鱼学习交流群】 目录 前言小程序版本更新机制…

Day.3 LeetCode刷题练习(反转链表)

题目&#xff1a; 例子&#xff1a; 分析题目&#xff1a; 分析题目&#xff0c;因为是一个单链表所以不能找到尾后往前改变&#xff0c;所以不妨换个思路从前往后进行修改链表链接关系 用到三个指针 指针cur指向所要改变的节点链接关系、指针prev指向所要改变节点的前一个节点…

白盒测试入门概念

白盒测试的度量 根据待测产品的内部实现细节来设计测试用例白盒测试的执行手段是可以涵盖单元测试、集成测试使用代码覆盖率作为白盒测试的主要度量指标 代码覆盖率常见概念 语句覆盖&#xff1a;每行代码都要覆盖至少一次判定覆盖&#xff1a;判定表达式的真假至少覆盖一次…

CSS文字阴影渐变动画效果

最近项目中需要一些简单的动画效果&#xff0c;就写了一个文字渐变的动画效果,纯CSS动画.文字加了一点阴影效果,看起来有发光哒感觉~ 效果如下图 大家可以自己拷贝代码亲自试一试 代码看下面 html <div class"son"> Particia </div>css .son {color…

SpringBoot2+Vue2实战(七)springboot集成jwt

一、集成jwt JWT依赖 <!-- JWT --><dependency><groupId>com.auth0</groupId><artifactId>java-jwt</artifactId><version>3.10.3</version></dependency> UserDto import cn.hutool.core.annotation.Alias; import …

【数据库】mysql 管理员密码丢失解决方案

本次操作环境是mysql5.7.24版本 问题&#xff1a;由于各种原因&#xff0c;数据库管理员密码丢失&#xff0c;无法登陆数据库 解决方法&#xff1a; 1、进入my.cnf文件进行修改配置 在[mysqld]下添加 skip-grant-tables 2、重启mysql服务 service mysql stop service mysql …

Fiddler如何延迟接口响应时间

需求描述&#xff1a;通过延迟接口响应时间来mock响应超时的测试场景 解决方法&#xff1a; 使用fiddler模拟接口延时请求&#xff0c;fiddler设置参数如下&#xff1a;

淘宝再夺顶级技术比赛CVPRNTIRE冠军,背后是这些提升用户体验的内容技术

不知不觉间&#xff0c;内容电商似乎已经成为人们生活中不可或缺的存在&#xff1a;在闲暇时间&#xff0c;我们已经习惯于拿出手机&#xff0c;从电商平台的直播间随手下单自己心仪的商品。 尽管优质的货品、实惠的价格、精致的场景布置、有趣的内容输出都是非常关键的影响因…

【JavaScript】文档注释详解

文章目录 什么是文档注释为什么要写文档注释不使用文档注释存在的隐患使用函数成员时的书写问题调用函数时功能使用问题 文档注释官方标签函数参数标签 param参数类型 {}参数注释对象属性属性注释使用带有对象属性注释的参数 返回值标签 returns注释 作者标签 author许可证标签…

spring cloud 之 eureka

Eureka概述 Spring Cloud封装了Netflix 公司开发的Eureka模块来实现服务治理&#xff0c;SpringCloud将它集成在其子项目spring-cloud-netflix中 在服务注册与发现中&#xff0c;有一个注册中心。当服务器启动的时候&#xff0c;会把当前自己服务器的信息比如服务地址通讯地址…

ubuntu 显卡驱动/cuda/cudnn

显卡驱动 https://www.bilibili.com/video/BV1Zc41137tU/?spm_id_from333.999.0.0&vd_sourced75fca5b05d8be06d13cfffd2f4f7ab5 使用recommended的驱动&#xff0c;open和无open的区别在于无open更适合发挥NVIDIA显卡的全部功能和性能&#xff0c;特别是GPU加速计算等任…

K8S集群安装与部署(Linux系统)

一、环境说明&#xff1a;CentOS7、三台主机&#xff08;Master&#xff1a;10.0.0.132、Node1&#xff1a;10.0.0.133、Node2&#xff1a;10.0.0.134&#xff09; 二、准备环境&#xff1a; 映射 关闭防火墙 三、etcd集群配置 安装etcd&#xff08;Master&#xff09; [ro…

[源码分析]-xxljob(1): 整体介绍

xxljob是一种分布式的调度框架&#xff0c;所谓分布式调度&#xff0c;是指调度器和执行器不在同一个进程里&#xff0c;因此必须进行远程服务调用&#xff0c;也需要考虑高可用问题。 但是由于调度器维护的数据是落库而在各个节点间共享的&#xff0c;因此不需要考虑数据的一…