Python Crash Course

This post is a quick intro to Python. Python is a 25 year old language. Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java.

Coming to the Code

To explain the various syntax’s of python, let us look at an example Which gives you ‘n’ Fibonacci numbers

n=eval(input("Enter the number"))
a=0
b=1
c=a+b
print(str(a)+",n"+str(b)+",n"+str(c)+",n")
for i in range(1,n-2):
    a=b
    b=c
    c=a+b
    print(str(c)+",") 

Types of data Structures

1.List
List is like an array: To declare a list just type in mylist=[]
2.Dictionary
It is exactly what it sounds like. A mixture of keys and values
To declare a dictionary type in dict = {}
3.Tuple
Tuple is basically a list but is immutable or cannot be changed ones a value is inserted
To declare a tuple use mytup=()

We will learn how to use these properly while solving questions in the future. If you wish you can visit the following link to learn more about the functions of these data structures.

Code Challenge

Let us now solve a quick problem from codechef

Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason for that was their really powerful army, also called as Mahasena.
Kattapa was known to be a very superstitious person. He believed that a soldier is "lucky" if the soldier is holding an even number of weapons, and "unlucky" otherwise. He considered the army as "READY FOR BATTLE" if the count of "lucky" soldiers is strictly greater than the count of "unlucky" soldiers, and "NOT READY" otherwise.
Given the number of weapons each soldier is holding, your task is to determine whether the army formed by all these soldiers is "READY FOR BATTLE" or "NOT READY".

Input:
The first line of input consists of a single integer N denoting the number of soldiers. The second line of input consists of N space separated integers A1, A2, …, AN, where Ai denotes the number of weapons that the ith soldier is holding.

Output:
Generate one line output saying "READY FOR BATTLE", if the army satisfies the conditions that Kattapa requires or "NOT READY" otherwise (quotes for clarity).

Examples:
Input:
1
1

Output:
NOT READY

Input:
1
2

Output:
READY FOR BATTLE

Input:
4
11 12 13 14

Output:
NOT READY

2 comments On Python Crash Course

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar

About Me

About Me

Hey, I am Thomas Ashish Cherian. What I cannot create, I do not understand.

Social Profiles