为了账号安全,请及时绑定邮箱和手机立即绑定

python 小目标3

Python Day 9

Today we will try the basic Arithmetic Operators including , + , - ,* ,/ and squares in Python.

Arithmetic Operators:

  1. The first line contains the sum of the two numbers.
  2. The second line contains the difference of the two numbers (first - second).
  3. The third line contains the product of the two numbers.
  4. The fourth line contains the division of the two numbers.

Solution:

def arith_op(a,b):
    n1=a+b
    n2=a-b
    n3=a*b
    n4=a/b
    print (n1,n2,n3,n4, sep="\n")

arith_op(2,3)

#Alternative Solution
print("%d\n%d\n%d"%(a+b,a-b,a*b))

Output

arith_op(2,3)
5
-1
6
0.6666666666666666

[caption id=“attachment_1787” align=“alignnone” width=“600”]image

BrooklynJohn / Pixabay[/caption]

Division:

Read two integers and print two lines. The first line should contain integer division,  a//b. The second line should contain float division, a /b.

a = int(input())
b = int(input())
print(a//b, a/b,  sep="\n")

Output:

1
1.33333333333

Square List:

Read an integer N. For all non-negative integers i< N , print i^2.

Solution:

[print(i*i) for i in range(n)]

Output:

0
1
4
9
16

Happy Practicing! 💤

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消