#1.wap to check whether a person is eligible to vote or Not
print("enter your age")
x=int(input())
if(x>18):
  print("you can vote")
else:
  print("you can't vote")
  
#3.WAP to check whether a number is even or odd
num = int(input("Enter a number: "))
if (num % 2) == 0:
   print(num,"is even")
else:
   print(num,"is odd")

#4.WAP to find maximum between two numbers
x=int(input("enter  first number"))
y=int(input("enter  second number"))
if(x>y):
  print(x,"is greater")
else:
  print(y,"is greater")
  
#5.WAP to find maximum between three numbers
print("enter three numbers")
x=int(input())
y=int(input())
z=int(input())
if(x>y and x>z):
  print(x,"is greater")
elif y>z:
  print(y,"is greater")
else:
  print(z,"is greater")
  
#6.WAP to chck whether a number is positive,negative or zero
print("enter any number")
x=int(input())
if(x>0):
  print(x,"is positive")
elif x<0:
  print(x,"is negative")
else:
  print(x,"is zero")
  
#7.WAP to check whether a number is leap year or Not
print("Enter year:")
year=int(input())
if (( year%400 == 0)or (( year%4 == 0 ) and ( year%100 != 0))):
    print(year,"is leap year")
else:
    print(year,"is not leap year")
#8.WAp to enter week number and print week day    

weekday = int(input("Enter weekday number "))

if weekday == 1 :
    print("\nMonday");

elif weekday == 2 :
    print("\nTuesday")

elif(weekday == 3) :
    print("\nWednesday")

elif(weekday == 4) :
    print("\nThursday")

elif(weekday == 5) :
    print("\nFriday")

elif(weekday == 6) :
    print("\nSaturday")
elif (weekday == 7) :
    print("\nSunday")

else :
    print("\nPlease enter any weekday number (1-7)") 
#9.WAP to input marks of five subjects 
print("enter marks of 5 subjects")
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
per=((a+b+c+d+e)/500)*100
print(per)
if per>=90:
  print("Grade A")
elif per>=80:
  print("Grade B")
elif per>=70:
  print("Grade C")
elif per>=60:
  print("Grade D")
elif per>=40:
  print("Grade E")
else:
  print("Grade F")
  
#10.wap to enter month number and print number of days in month using if else  
month = int(input())
year = int(input())
if(month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12):
	print("Number of days is 31")
elif((month == 2) and ((year%400==0) or (year%4==0 and year%100!=0))):	
	print("Number of days is 29")
elif(month == 2):
	print(" of days is 28")
else:
	print("Number of days is 30")
#11.write a program to print all natural numbers from 1 to n using loop.

num=int(input("Please enter maxinmum number: "))
print("Natural numbers 1 to ",num )
for i in range(1,num+1):
 print (i)
 
#12.WAp a program to input week no and print day of week name using switch case.
day=int(input())
def week(i):
  switcher={
    1:'Sunday',
    2:'Monday',
    3:'Tuesday',
    4:'Wednesday',
    4:'Thursday',
    6:'Friday',
    7:'Saturday'
    }
  return switcher.get(i,"Invalid day of week")
print(week(day))

#14.WAP to check relation between two numbers i.e, less than or eqyal to.

a1=int(input())
a2=int(input())
if a1>a2:
  print("Numbers 1 is greater than number 2")
elif a2>a1:
  print("Numbers 2 is greater than number 1")
else:
  print("Both are equal")
  
#15.A company decided to give bonus of 5% to employee if his/her year of service oa more than 5 years   
salary = int(input())#enter your salary
service_years = int(input())#enter your service years
if service_years > 5:
  bonus=(salary)*5/100
  salary=salary+bonus
  print("Yours salary(+Bonus) = ",salary)
else:
  print("You are not eligible for bonus as you have less service years.")
     
     
#16. Take input of age of 3 people by user and determine oldest and youngst among them.
a1=int(input())
a2=int(input())
a3=int(input())
def largest(n1, n2, n3):
    if (n1 > n2) and (n1 > n3):
        largest_num = n1
    elif (n > n1) and (n2 > n3):
        largest_num = n2
    else:
        largest_num = n3
    print("The largest of the 3 numbers is : ", largest_num)
def smallest(n1, n2, n3):
    if (n1 < n2) and (n1 < n3):
        smallest_num = n1
    elif (n2 < n1) and (n2 < n3):
        smallest_num = n2
    else:
        smallest_num = n3
    print("The smallest of the 3 numbers is : ", smallest_num)
largest(a1,a2,a3)
smallest(a1,a2,a3)



    
     
by

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset = {"iPhone","Pixel","Samsung"}
print(myset)

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)

Supported Libraries

Following are the libraries supported by OneCompiler's Python compiler

NameDescription
NumPyNumPy python library helps users to work on arrays with ease
SciPySciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation
SKLearn/Scikit-learnScikit-learn or Scikit-learn is the most useful library for machine learning in Python
PandasPandas is the most efficient Python library for data manipulation and analysis
DOcplexDOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling