0% found this document useful (0 votes)
3 views3 pages

Python Contest Guide

This document is a guide for beginners to lower-intermediate Python programming, covering essential topics such as input/output, conditional statements, loops, list and string manipulation, functions, built-in functions, sorting and searching, dictionaries and sets, recursion, and a problem-solving template. It provides code snippets and examples for each topic to illustrate their usage. The guide aims to equip readers with foundational skills for programming contests.

Uploaded by

mrrobotmunna234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Python Contest Guide

This document is a guide for beginners to lower-intermediate Python programming, covering essential topics such as input/output, conditional statements, loops, list and string manipulation, functions, built-in functions, sorting and searching, dictionaries and sets, recursion, and a problem-solving template. It provides code snippets and examples for each topic to illustrate their usage. The guide aims to equip readers with foundational skills for programming contests.

Uploaded by

mrrobotmunna234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Programming Contest Guide (Beginner to Lower-Intermediate)

1. Input/Output

Basic input:

name = input()

Input with prompt:

age = int(input('Enter age: '))

Multiple inputs:

a, b = map(int, input().split())

Output:

print('Hello')

print(f'Value is {a}')

2. Conditional Statements

if x > 0:

print('Positive')

elif x == 0:

print('Zero')

else:

print('Negative')

3. Loops

for i in range(5):

print(i)

while x > 0:

x -= 1

print(x)
Python Programming Contest Guide (Beginner to Lower-Intermediate)

4. List & String Manipulation

List:

arr = [1, 2, 3]

arr.append(4)

arr.sort()

String:

s = 'hello'

print(s.upper(), s[::-1])

5. Functions

def add(a, b):

return a + b

print(add(2, 3))

6. Useful Built-in Functions

len(), range(), max(), min(), sum(), sorted()

Example:

nums = [4, 2, 8]

print(max(nums), sum(nums))

7. Sorting & Searching

nums = [5, 2, 1]

nums.sort()

Binary Search (from bisect module):

from bisect import bisect_left


Python Programming Contest Guide (Beginner to Lower-Intermediate)

8. Dictionaries & Sets

d = {'a': 1, 'b': 2}

print(d['a'])

s = set([1,2,3])

s.add(4)

9. Recursion Example

def fact(n):

if n == 0: return 1

return n * fact(n-1)

print(fact(5))

10. Problem Solving Template

t = int(input())

for _ in range(t):

n = int(input())

arr = list(map(int, input().split()))

# solve here

You might also like