Python

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1. What is python?

Python is a popular programming language. It is created by Guido Van Rossum and released
in 1991. It is used for :- Web development, Software Development, Mathematic, System
Scripting.
2. What can Python do?
 Python can be used on a serve to create3 web applications.
 Used along site software to create work flows.
 Connect to database system. It also read and modify files.
 Used to handle big data and perform complex mathematics.
 Used for rapid prototyping.
3. Why python?
 Python works on deferent platforms.
 Python has a simple syntax similar to the English language.
 Python has syntax that allows developers to write programmes with fewer lines then
some other programming language.
4. Reserve Words:- AND,BREAK,ASSERT,DEF,DEL,IT,ELITE,FOR
5. Indention :- White space beginning the line.
6. Arithmetic operator: +,-,*,/,%,//,**
7. Comparison operator: ==,!=,<,>,<=,>=
8. Unary operator:- if one operand compliment number . Exm:- b=-(a)
9. Bitwise operator:- &,|,^,~
10. Shift operator:- <<,>>
11. Logical operator: &&,||,!
12. Membership operators:- in, not in
13. String:- concatenation . Ex:- print(“abc”+”def”)
Output- abcdef
14. Repeat operation- Input :- print(“hello”,*5)
Output:- hello, hello, hello, hello, hello
Slice of String-
Input: String = 'GlobalInstitue'
s1 = slice(3)
s2 = slice(1, 5, 2)
print("String slicing")
print(String[s1])
print(String[s2])
Output :- String slicing
Glo
lb
15. Tuple:- A tuple is similar to the list as it also consists of an of values separates by ‘,’and
enclosed within parenthesis. The main defines between list and tuple is that you can change
the value in a list but not in a tuple. These means that tuple is read only data type.
16. Write a program to check weather a given number positive or not:-

Input : Num=int(input("Enter a Number : "))


if (Num>0):
    print("The Number is positive")
elif(Num==0):
    print("The Number is zero")
else:
    print("The Number is negative")
Output: Enter a Number : 2
The Number is positive

17. Write a program to check a given number Odd Or Even :


Input: num = int(input("Enter a number: "))
if (num % 2) == 0:

   print("Even Number")

else:

   print("Odd Number")

Output: Enter a number: 5


Odd Number

18. Write a program to find the largest among three numbers:


Input: num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


   largest = num1
elif (num2 >= num1) and (num2 >= num3):
   largest = num2
else:
   largest = num3

print("The largest number is", largest)


Output:- Enter first number: 10
Enter second number: 50
Enter third number: 30
The largest number is 50.0
19. Write a program to check given number is leap year or not leap year.
Input: year=int(input("Enter a Year : "))
if (year % 400 == 0) and (year % 100 == 0):
    print("leap year")
elif (year % 4 ==0) and (year % 100 != 0):
    print("leap year")
else:
    print(" not a leap year") output:- 2000 is leapyear
20. Write a program to check given number is vowel or consonant.:
Input: ch = input("Enter the character : ")
if(ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u' or ch == 'A' or ch
== 'E' or ch == 'I' or ch == 'O' or ch == 'U'):
  print("Vowel")
else:
  print("Consonant")
Output:- Enter the character : d
Consonant
21. Write a program to calculate a roots of quadratic equation:
Input: a=float(input("Enter First Number : "))
b=float(input("Enter Second Number: "))
c=float(input("Enter Third Number : "))
d=b*b-4*a*c
root1=(-b+cmath.sqrt(d))/(2*a)
root2=(-b-cmath.sqrt(d))/(2*a)
print("The Value of root {0} and {1}".format(root1,root2))

22. Braek statement :- the break statement is used to terminate the execution of the nearest n
closing loop in within it appears. The statement is wildly used with for loop and while loop.
When the compiler encounters a break statements, the control passes to the statement that
follows the loop in which the break statement appears.
i=0
While(i>10):
Print(i,end=””)
If(i==5):
Break
i=i+1
23. Continue Statement:- the continue statement can appear in the body of a loop when the
compiler encounters a continue statements, then the rest of the statements in the loop are
skipped and the control is unconditionally transfer to the loop continues of the nearest
enclosing loop.
i=0
While(i>10):
If(i==5):
Continue
Print(i,end=””)
i=i+1
24. While loop:- While loop provide a mechanism to repeat one or more statement while a
particular condition is true.

You might also like