Zero to Hero 1-1

First Acquaintance

Ultimate Python Mastery Course | Codefinity

 教学大纲:  【需优化】

Introduction to Python


简介:
       
        完成本课程后,您将能够编写基本的Python代码,了解其语法,并设置Python开发环境。您将具备开始编程之旅的技能,并为进一步学习奠定坚实的基础。

The Very First Steps

Python 是一种高级解释型语言。高级语言具有机器无法直接理解的抽象语法。

让我们深入研究并使用 Python 打印第一条消息。我们将为此使用 print() 函数。当您想要打印特定文本时,只需将其括在引号中,例如“...”或“...”。如果不这样做,Python 会假定您指的是变量(但我们稍后会讲到)。

要打印句子,请使用以下代码:

print("Some message")

Comments 评论

Congratulations! As your code grows in size, it can become challenging to understand each part, even if you're the author.

That's why it's essential to get in the habit of leaving comments in your code. Comments help clarify the purpose or function of a specific code segment.

To designate a line as a comment, start it with the # symbol.

For instance:

Output:   输出 

print('Message 1')
print('Message 2')

But remember, if you put a # before the print( ) statement, that line won't run

# print('Message 1')
print('Message 2')

Some Simple Math

注释 : # 

数学符号:+  - *  /

# Calculate first expression
print(2580+198)
# Calculate second expression
print(23*42)
# Calculate third expression
print(1512/27)
Task

2580 added to 198.
23 times 42.
1512 divided by 27.


More Challenging Math 更具挑战性的数学

Python提供了几个额外的数学运算,包括:

  • //-底数除法或整数除法;
  • %-模数或除法后的余数;
  • **-求幂或升至幂。

值得注意的是,在Python中不能使用传统的^符号进行求幂运算,因为它会产生不同的结果。这些操作的语法反映了基本算术的语法。例如,18//4的结果为4,因为我们从除法中取整数(实际结果为4.5)。14%5等于4,因为当我们将14除以5时,余数为4。4**3的结果是64,因为4乘以3个4等于64。
 

# Default division
print(18 / 4)
# Floor division
print(18 // 4)
# Remainder of the division
print(18 % 4)
# Raising to the power of 4
print(18 ** 4)

Output:

4.5

4

2

104976

# Calculate the integer part of division
print(234//32)

# Calculate the remainder of division
print(356%17)

7

16

Challenge   为什么这些操作有帮助?


例如,想象一下这样的场景:你有50美元,你想买尽可能多的饼干包,每包售价6美元。您正在尝试计算可以购买的最大包数以及您将收到的更改。使用上述操作,让我们练习一下!
注:
        记住,当将一个数字提升到幂时,应该使用**运算符。


任务:


在第二行,计算0.99的365次幂。
在第四行,计算1.01到365的幂。
提示
这里的要点是什么?如果你每天只进步1%,到年底,你会进步37倍。所以,在你的学习之旅中继续前进!:)e、 你可以很容易地解决这个问题。一切都清楚了吗?

# Calculate the first expression
print(0.99**365)
# Calculate the second expression
print(1.01**365)

# Calculate the first expression
print(0.99**365)
# Calculate the second expression
print(1.01**365)

转义字符

在任务的第三行中,您可以看到“”符号。它是转义字符之一,在控制台中打印内容时非常有用。

\n  换行符          -移动到下一行。
\t   水平选项卡   -添加用于格式化的选项卡空间。
\\   反斜杠(\)  -在字符串中包含一个文字反斜杠。
\'   单引号(')  -允许在字符串中使用单引号。
\“   双引号(”) -在字符串中包含双引号。 


任务


在第三行,在问候语后打印你的名字。
将2894除以274得到一个整数结果,然后将该结果提高到4的幂。这是第6行。
注释掉第一行和第七行,这样它们就不会显示在控制台中。


注:
        不要混淆/和//运算符。只有//运算符返回整数结果。

print("Code start")  #注释掉
# Replace name
print("Hello, my name is", "\"___\"")#输入名字
print("and I'm learning Python.")
# Calculate math expression
print((___ 274)___) #输入2894整除294,并进行4次幂的计算
print("Code end")  #注释掉


答题:
#print("Code start")
# Replace name
print("Hello, my name is", "\"zheng\"")
print("and I'm learning Python.")
# Calculate math expression
print((2894//274)**4)
#print("Code end")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值