Python Lecture 1 Problem Set 1: Arithmetic
Topic • Arithmetic Operation • Operator (Arithmetic Operator) • More Built in Function • Module (Math) • Problem Set 1: Arithmetic (15)
Summation of two number. a = int(input()) b = int(input()) sum = a + b print(sum)
Difference of two number. a = int(input()) b = int(input()) diff = a - b print(diff)
Product of two number. a = int(input()) b = int(input()) pro = a * b print(pro)
Quotient of two number. a = int(input()) b = int(input()) quo = a / b print(quo)
Reminder of two number. a = int(input()) b = int(input()) rem = a % b print(rem)
Find Exponent (a^b). [1] a = int(input()) b = int(input()) ## Exponent with Arithmetic Operator ## Syntax: base ** exponent exp = a ** b print(exp)
Find Exponent (a^b). [2] a = int(input()) b = int(input()) # Exponent with Built-in Function # Syntax: pow(base, exponent) exp = pow(a,b) print(exp)
Find Exponent (a^b). [3] a = int(input()) b = int(input()) # Return Modulo for Exponent with Built-in Function # Syntax: pow(base, exponent, modulo) exp = pow(a,b,2) print(exp)
Find Exponent (a^b). [4] a = int(input()) b = int(input()) # Using Math Library import math exp = math.pow(a,b) print(exp)
Floor Division. a = int(input()) b = int(input()) div = a // b print(div) a = float(input()) b = float(input()) div = a // b print(div)
Find absolute difference of two number. [1] a = int(input()) b = int(input()) absdif = abs(a - b) print(absdif)
Find absolute difference of two number. [2] import math a = float(input()) b = float(input()) absdif = math.fabs(a - b) print(absdif)
Average of three numbers. a = float(input()) b = float(input()) c = float(input()) sum = a + b + c avg = sum/3 print(avg)
Area of Triangle using Base and Height. b = float(input()) h = float(input()) area = (1/2) * b * h print(area)
Area of Triangle using Length of 3 sides. import math a = float(input()) b = float(input()) c = float(input()) s = (a+b+c) / 2 area = math.sqrt(s*(s-a)*(s-b)*(s-c)) print(area)
Area of Circle using Radius. import math r = float(input()) pi = math.pi area = pi * r**2 # area = pi * pow(r,2) print(area)
Convert Temperature Celsius to Fahrenheit. # (C/5) = (F-32)/9 celsius = float(input()) fahrenheit = 9 * (celsius/5) + 32 print(fahrenheit)
Convert Temperature Fahrenheit to Celsius. # (C/5) = (F-32)/9 fahrenheit = float(input()) celsius = (fahrenheit-32)/9 * 5 print(celsius)
Convert Second to HH:MM:SS. # 1 Hour = 60 Minutes # 1 Minute = 60 Seconds totalSec = int(input()) hour = int(totalSec/3600) remSec = int(totalSec%3600) minute = int(remSec/60) second = int(totalSec%60) print("{}H {}M {}S".format(hour,minute,second)) #print(f"{hour}H {minute}M {second}S") # 1 Hour = 60 Minutes # 1 Minute = 60 Seconds totalSec = int(input()) hour = totalSec//3600 remSec = totalSec%3600 minute = remSec//60 second = totalSec%60 print("{}H {}M {}S".format(hour,minute,second)) #print(f"{hour}H {minute}M {second}S")
Built-in Function • abs(x) • pow(x,y) • https://docs.python.org/3.6/library/functions.html
Math Module • math.pow(x, y) • math.sqrt(x) • math.pi • https://docs.python.org/3.6/library/math.html
Problem Set 1: Arithmetic (15) • Summation of two number. • Difference of two number. • Product of two number. • Quotient of two number. • Reminder of two number. • Find Exponent (a^b). • Floor Division. • Find absolute difference of two number. • Average of three numbers. • Area of Triangle using Base and Height. • Area of Triangle using Length of 3 sides. • Area of Circle using Radius. • Convert Temperature Celsius to Fahrenheit. • Convert Temperature Fahrenheit to Celsius. • Convert Second to HH:MM:SS.
Any Question?
Prepared by Mun Al Mamun President East West University Robotics Club munewu@gmail.com T h i s s l i d e i s p r o v i d e a s a c o u r s e m a t e r i a l i n t h e w o r k s h o p “ W o r k s h o p O n P y t h o n P r o g r a m m i n g ” O r g a n i z e d b y E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b

Lecture 1 python arithmetic (ewurc)

  • 2.
  • 3.
    Topic • Arithmetic Operation •Operator (Arithmetic Operator) • More Built in Function • Module (Math) • Problem Set 1: Arithmetic (15)
  • 4.
    Summation of twonumber. a = int(input()) b = int(input()) sum = a + b print(sum)
  • 5.
    Difference of twonumber. a = int(input()) b = int(input()) diff = a - b print(diff)
  • 6.
    Product of twonumber. a = int(input()) b = int(input()) pro = a * b print(pro)
  • 7.
    Quotient of twonumber. a = int(input()) b = int(input()) quo = a / b print(quo)
  • 8.
    Reminder of twonumber. a = int(input()) b = int(input()) rem = a % b print(rem)
  • 9.
    Find Exponent (a^b).[1] a = int(input()) b = int(input()) ## Exponent with Arithmetic Operator ## Syntax: base ** exponent exp = a ** b print(exp)
  • 10.
    Find Exponent (a^b).[2] a = int(input()) b = int(input()) # Exponent with Built-in Function # Syntax: pow(base, exponent) exp = pow(a,b) print(exp)
  • 11.
    Find Exponent (a^b).[3] a = int(input()) b = int(input()) # Return Modulo for Exponent with Built-in Function # Syntax: pow(base, exponent, modulo) exp = pow(a,b,2) print(exp)
  • 12.
    Find Exponent (a^b).[4] a = int(input()) b = int(input()) # Using Math Library import math exp = math.pow(a,b) print(exp)
  • 13.
    Floor Division. a =int(input()) b = int(input()) div = a // b print(div) a = float(input()) b = float(input()) div = a // b print(div)
  • 14.
    Find absolute differenceof two number. [1] a = int(input()) b = int(input()) absdif = abs(a - b) print(absdif)
  • 15.
    Find absolute differenceof two number. [2] import math a = float(input()) b = float(input()) absdif = math.fabs(a - b) print(absdif)
  • 16.
    Average of threenumbers. a = float(input()) b = float(input()) c = float(input()) sum = a + b + c avg = sum/3 print(avg)
  • 17.
    Area of Triangleusing Base and Height. b = float(input()) h = float(input()) area = (1/2) * b * h print(area)
  • 18.
    Area of Triangleusing Length of 3 sides. import math a = float(input()) b = float(input()) c = float(input()) s = (a+b+c) / 2 area = math.sqrt(s*(s-a)*(s-b)*(s-c)) print(area)
  • 19.
    Area of Circleusing Radius. import math r = float(input()) pi = math.pi area = pi * r**2 # area = pi * pow(r,2) print(area)
  • 20.
    Convert Temperature Celsiusto Fahrenheit. # (C/5) = (F-32)/9 celsius = float(input()) fahrenheit = 9 * (celsius/5) + 32 print(fahrenheit)
  • 21.
    Convert Temperature Fahrenheitto Celsius. # (C/5) = (F-32)/9 fahrenheit = float(input()) celsius = (fahrenheit-32)/9 * 5 print(celsius)
  • 22.
    Convert Second toHH:MM:SS. # 1 Hour = 60 Minutes # 1 Minute = 60 Seconds totalSec = int(input()) hour = int(totalSec/3600) remSec = int(totalSec%3600) minute = int(remSec/60) second = int(totalSec%60) print("{}H {}M {}S".format(hour,minute,second)) #print(f"{hour}H {minute}M {second}S") # 1 Hour = 60 Minutes # 1 Minute = 60 Seconds totalSec = int(input()) hour = totalSec//3600 remSec = totalSec%3600 minute = remSec//60 second = totalSec%60 print("{}H {}M {}S".format(hour,minute,second)) #print(f"{hour}H {minute}M {second}S")
  • 23.
    Built-in Function • abs(x) •pow(x,y) • https://docs.python.org/3.6/library/functions.html
  • 24.
    Math Module • math.pow(x,y) • math.sqrt(x) • math.pi • https://docs.python.org/3.6/library/math.html
  • 25.
    Problem Set 1:Arithmetic (15) • Summation of two number. • Difference of two number. • Product of two number. • Quotient of two number. • Reminder of two number. • Find Exponent (a^b). • Floor Division. • Find absolute difference of two number. • Average of three numbers. • Area of Triangle using Base and Height. • Area of Triangle using Length of 3 sides. • Area of Circle using Radius. • Convert Temperature Celsius to Fahrenheit. • Convert Temperature Fahrenheit to Celsius. • Convert Second to HH:MM:SS.
  • 26.
  • 27.
    Prepared by Mun AlMamun President East West University Robotics Club munewu@gmail.com T h i s s l i d e i s p r o v i d e a s a c o u r s e m a t e r i a l i n t h e w o r k s h o p “ W o r k s h o p O n P y t h o n P r o g r a m m i n g ” O r g a n i z e d b y E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b