Training Site
Sideways banner

Python

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 100 megabytes
Time limit: 1.0 seconds

I/O and Documentation

Download Python.

Examples

Write a program to add two numbers and print the result. Numbers will be space separated on a single line (see the sample input and output below). You may copy-paste the below example if you understand it.

nums = input().split()
total = int(nums[0]) + int(nums[1])
print(total)


Or, for those who are more experienced, a one-line solution is:

print(sum(map(int, input().split())))


Submit

  • Go to the submit tab and upload the addition program above by copy-pasting and selecting Python in the language dropdown.
  • Do not use input prompts e.g. input("Numbers: ") because the string "Numbers: " will be evaluated as incorrect output. See the walk-through below to understand why.
  • Walk-through example and explanation.
  • Understanding submission feedback.

Note: There are two submission options for Python programs. You may select Python 3.8 or Python 3.6 (PyPy 7.3). PyPy is a just-in-time compiler which is often faster than the standard C Python interpreter. The compromise is the older version of Python. Newer NZIC problems should be solvable with C Python (unless specified) but other problems on this site might not be. If your Python solution is timing out it might be worth trying PyPy.

Sample Explanation

3 + 4 = 7

  • Sample Input 1

    3 4
    

    Sample Output 1

    7