An Introduction to Interactive Programming in Python (Part 1) - Week 0

An Introduction to Interactive Programming in Python (Part 1) - Week 0 - Statements, expressions, variables

Quiz 0

1.

Which of the following are syntactically correct strings?
Try each of them in CodeSkulptor.

  • “Hello
  • (CHECKED) “Hello”
  • (CHECKED) “It’s a beautiful day.”
  • (CHECKED) ‘Hello’
  • Hello

2.

To display a value in the console, what Python keyword do you use?

print

3.

In the following code, there is one line starting with #. What does this line mean to Python?

tax_rate = 0.15
income = 40000
deduction = 10000

# Calculate income taxes
tax = (income - deduction) * tax_rate
print tax
  • (CHECKED) This is a comment aimed at the human reader. Python ignores such comments.
  • This is a syntax error.
  • This text is used as a file name for the code.
  • This text is printed on the console.

4.

Which of the following arithmetic expressions are syntactically correct?
Try each of them in CodeSkulptor.

  • (CHECKED) (8 + (1 + (2 * 4) - 3))
  • 5 * 3 (7 - 2)
  • 9 + * 4
  • (CHECKED) 8/ -2
  • (CHECKED) 5 - 1 - 3 - 7 - 0

5.

You would like to make it so that the variable ounces has the value 16, thus representing one pound. What simple Python statement will accomplish this?

  • 16 = ounces
  • ounces := 16
  • ounces == 16
  • (CHECKED) ounces = 16

6.

A gram is equal to 0.035274 ounces. Assume that the variable mass_in_ounces has a value representing a given mass in ounces. Which Python statement below uses the variable mass_in_ounces to compute an equivalent mass mass_in_grams expressed in grams?

Think about it mathematically, but also test these expressions in CodeSkulptor. If you are still confused, you might check out the student tutorial video by Kelly on unit conversions in the “Concepts and Examples” page.

  • mass_in_grams = 0.035274 / mass_in_ounces
  • mass_in_grams = mass_in_ounces * 0.035274
  • mass_in_ounces = 0.035274 * mass_in_grams
  • (CHECKED) mass_in_grams = mass_in_ounces / 0.035274

7.

Which of the following can be used as a variable name?
Try using each in CodeSkulptor.

  • 16ounces
  • my-number
  • (CHECKED) MYnumber
  • (CHECKED) number123

8.

Assume you have values in the variables x and y. Which statement(s) would result in x having the sum of the current values of x and y?

Test your answer in CodeSkulptor.

  • (CHECKED) x = x +y
  • (CHECKED) x = y + x
  • y += x+y
  • y += x

9.

Python file names traditionally end in what characters after a period? Don’t include the period.

py

10.

We encourage you to save your CodeSkulptor Python files where?

  • On your computer only
  • Nowhere — CodeSkulptor automatically saves your files for you
  • (CHECKED) In “the cloud” and on your computer
  • In “the cloud” only

Mini-project #0 - “We want… a shrubbery!” (optional)

# program template for mini-project 0

# Modify the print statement according to 
# the mini-project instructions

print "We want... a shrubbery!"

-eof-

Python交互式编程入门》是一门介绍如何使用Python进行交互式编程的课程。在这门课程中,学习者将学习如何使用Python编写简单的程序并与之进行交互。 首先,课程将介绍Python的基本语法和编程概念。学习者将学习如何定义变量、使用条件语句和循环、编写函数以及处理列表和字典等数据结构。 接下来,课程将介绍Python交互式编程的概念。学习者将学习如何使用Python的交互式命令行界面进行编程,并了解如何与Python解释器进行交互。他们将学习如何编写单行和多行的Python代码,并立即查看结果。 在这门课程中,学习者还将学习如何使用Python编写简单的图形用户界面(GUI)应用程序。他们将学习如何使用Python的GUI库来创建窗口、按钮、文本框等界面元素,并学习如何为这些元素添加交互功能。 此外,课程还将涵盖一些常见的Python编程任务,如文件操作、网络编程和数据可视化。通过这些任务的实践,学习者将能够更好地理解Python交互式编程的应用。 该课程注重实践,学习者将通过编写小型项目和解决编程问题来应用所学知识。他们将有机会与其他学习者一起合作,分享代码和解决方案,并从其他人的经验中学习。 总之,《Python交互式编程入门》是一门适合初学者的课程,它将帮助学习者掌握Python编程的基本概念和技能,并提供实践经验和项目练习。通过这门课程的学习,学习者将能够熟练地运用Python进行交互式编程,并在日后的编程任务中受益。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值