美文网首页大数据
Python 小目标3

Python 小目标3

作者: 不连续小姐 | 来源:发表于2019-03-07 00:55 被阅读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! 💤

Reference:
https://www.hackerrank.com

相关文章

  • Python 小目标3

    Python Day 9 Today we will try the basic Arithmetic Opera...

  • 立志精通Python

    今天小目标没坚持几个,到处瞎逛,全是python。 python可以做什么,python爬取…python零基础资...

  • 我的学习困境

    一颗火热的心抵不过时光的消磨。 18年年末个自己制定了3个学习目标,大目标是学习python,小目标是学习英...

  • Python 小目标11

    Python Day 17: Polar Coordinate in Python " You are round...

  • Python 小目标7

    Today we will try to work with Python Strings Task1:Pytho...

  • Python 小目标8

    Python day 14 Who is the True Lucky Guy? In Wechat red-pa...

  • Python 小目标 9

    Python Day 15 Love Earth Day ❤ the Earth day is coming! m...

  • Python 小目标10

    Python Day 16 1. distinct Average suppose we want to find...

  • python 小目标1

    Python Day 7 Problem 1: Given an array of integers, find ...

  • Python 小目标2

    Python Day 8 Problem 1: Factorial Write a factorial funct...

网友评论

    本文标题:Python 小目标3

    本文链接:https://www.haomeiwen.com/subject/mkfqpqtx.html