We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Introduction
  4. Arithmetic Operators
  5. Tutorial

Arithmetic Operators

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

First, the code stubs read two integers from STDIN:

#Python 2
a = int(raw_input())
b = int(raw_input())

#Python 3
a = int(input())
b = int(input())

In the above statements, raw_input() and input() are the Python 2 and Python 3 methods to read lines from STDIN. The methods return a string by default. Since this problem uses numeric data, the input value must be converted to an integer. Convert a string to an integer using int().

Now, a bit about Arithmetic Operators

The three basic arithmetic operators are the following:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)

There are several division methods that will be discussed in the next challenge. Of the three operators shown, multiplication takes precedence over addition and subtraction. Addition and subtraction have equal precedence.

For example:
- Given , the parentheses are unnecessary due to precedence. Multiplication is performed before addition. This equation can be written more simply as .
- To multiply by , write .

Solve Problem

tutorial details


Need Help?


View discussions
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy