0% found this document useful (0 votes)
9 views17 pages

Python1

Uploaded by

annoyingraptor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
9 views17 pages

Python1

Uploaded by

annoyingraptor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 17

Shyamsir Python Language 78 74 39 11 91

Python is a coding language

Python is an interpreted, object-oriented, high-level programming language.

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

1. Web development
2. Desktop app and software development
3. Processing big data and performing mathematical computations
4. System scripting.
5. Machine Learning and AI

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

In 1980s, by Guido van Rossum at


Centrum Wiskunde & Informatica (CWI) in
the Netherlands as a successor to the ABC
programming language.

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Examples#

1 print(“Hello”)
2 print(“Hello\nhi”)
3 print(“hello\thow are u?”)
4 a=5
print(a)
print(“a”)
print(“No = “,a)
5 a=50
b=10
print(“Add = “,a+b,”Sub=”,a-b)

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

What is Variable?

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Rules of Variable

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Basic expression programs:


1. Write a program to print “HELLO WORLD”

Hint print(“…

2. Write a program to print “Name and Address”

Hint print(“…

3. Write a program to print no and its square.

Hint a=5
print(“

4. Write a program to take two numbers and print Addition, Multiplication,


Subtraction, Division.

Hint a=20 , b=2


print
print
print
print

5. Write a program to find the area of a circle (3.14*r*r)

Hint r=10
print(

6. Write a program to calculate simple interest using I = PRN/100 (P= Principle


amount, R = Rate of Interest, N = Number of Years)

Hint p=10000,r=2,n=2
print(

7. Write a program to find the area of a Triangle (0.5*H*B)

Hint H=100,B=200
print(

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Take value from the user

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Input/Output programs:
1. Write a program to print no and its square.

Hint a=int(input(…..
print(…

2. Write a program to take two numbers and print Addition, Multiplication,


Subtraction, Division.

Hint a=int(input(…. , b=int(input(….


print(

3. Write a program to find the average temperature of five sunny days.

Hint day1=int(input(… , day2,day3,day4,day5


print

4. Write a program to find the area of a circle (3.14*r*r)

Hint r=float(input(…

5. Write a program to calculate simple interest using I = (P*R*N)/100 (P= Principle


amount, R = Rate of Interest, N = Number of Years)

Hint p=float(input( , r= float(input( , n = float(input(


print(“Interest =

6. Write a program to find the area of a Triangle (0.5*H*W)

Hint h=float(input( , w= float(input(


print(“Area of Triangle =

7. Convert meter to centimetre

Hint meter=float(input(
print(“Centimetre =

8. Write a program to enter the temperature in feranhit and convert it to


Celsius.[C=(f-32)*5/9]

Hint f=float(input(
print(“Celsius =

9. Write a program to calculate Gross Salary and Net Salary print Grade of employee

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Gross Salary = basic + da + hra + ma + Itc + va


BASIC = 8000 ma= 10% of basic
da = 52% of basic ltc= 5% of basic
hra= 10% of basic va= 10% of basic

Net Salary = Gross Saiary - PF


Hint
salary=int(input(“Enter Salary
Da=salary*
Ma=
Hra=
Va=
Netsalary=
print(“Final Salary =>

10. Write a program to swap contents of the two variables

Hint a=int(input( , b=int(input


print(“Before swap a = “,a ,” b = “,b)
logic..
print(“After swap a = “,a ,” b = “,b)

11. Write a program to swap contents of the two variables without use of third variable

Hint a=int(input( , b=int(input


print(“Before swap a = “,a ,” b = “,b)
logic..
print(“After swap a = “,a ,” b = “,b)

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Operators
Arithmetic Operators
Operator Name Example

+ Addition x+y

- Subtraction x-y

* Multiplication x*y

/ Division x/y

% Modulus x%y

** Exponentiation x ** y

// Floor division x // y

Logical Operators
Operator Description Example

and Returns True if both x < 5 and x < 10


statements are true
Or Returns True if one of the x < 5 or x < 4
statements is true
Not Reverse the result, returns not(x < 5 and x < 10)
False if the result is true

Comparison Operators
Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x >y
< Less than x <y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Assignment Operators
Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3

%= x %= 3 x=x%3

//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3

&= x &= 3 x=x&3

|= x |= 3 x=x|3
^= x ^= 3 x=x^3

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

What is Conditional/Decision making


Statements in Python?

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

Operators or say conditions

• Equals: a == b
• Not Equals: a != b
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b
• Divisible by: a%7==0

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91

If else programs
1) Find out Maximum between 2 values
(Example : Enter no1 => 22 , Enter no2 =>33 then output will be 33 is max)

2) Enter one value and check whether that no is 5 or not?


(Example : Enter no => 5, Yes no is 5 , if 6 then Sorry no is not 5)

3) Enter one value and check whether that no is greater than 5 or not?
(Example : Enter no => 57, Yes no is > 5 , if 3 then Sorry no is <5)

4) Write a C program to accept two integers and check whether they are equal or not.
(Example : Enter no1 => 57, Enter no2 => 57
Yes both are equal)

5) Write a C program to read the age of a candidate and determine whether it is


eligible for casting his/her own vote.
(Example : Enter your age => 16
Sorry you are not eligible for vote)

6) Find out whether the given no is positive or negative


(Example : Enter no => 22 then output will be 22 is positive , -3 is negative , no
is 0)

7) Find out whether the give no is odd or even or 0.


(Example : Enter no => 22 then output will be 22 is even , 23 is odd , no is 0)

8) Enter 3 subjects marks , print total , and if total>50 then display Pass else display
Fail
(Example : Enter marks of Hindi => 22 Enter marks of English =>30 Enter marks
of SS => 35 then output will be Your total 117 , you are pass)

9) Enter 3 subjects marks , print total , and if total is between 0-50 then display C
grade , 50-100 B grade and > 100 then A grade
(Example : Enter marks of Hindi => 22 Enter marks of English =>30 Enter marks
of SS => 35 then output will be Your total 117 ,you got A grade)

10) Write a C program to find the largest of three numbers.


(Example: Enter no1 => 12 Enter no2 =>25 Enter no3 => 52
Output will be
The 3rd Number is the greatest among three

11) Write a C program to find whether a given year is a leap year or not.
(Example: Enter year => 2020 , Output will be Year is leap year)

12) Write a Python program to input any alphabet and check whether it is vowel or
consonant.
(Example: Enter character => a
It's a vowel)
13) Write a Python program to input week number and print week day.
(Example: Enter week number => 2
Tuesday)
14) Write a Python program which takes two values and choice 1 2 3 4 , if user press
1 then display addition , 2 for subtraction , 3 for multiplication , 4 for division.
(Example: Enter no1 => 22

www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
Enter no2 => 2
Enter 1 for Add
Enter 2 for Sub
Enter 3 for Mul
Enter 4 for Div
Enter =>2
Output : 24)

15) Write a Python program which takes two values and choice + - * / , if user press
+ then display addition , - for subtraction , * for multiplication , / for division.
(Example: Enter no1 => 22
Enter no2 => 2
Enter + for Add
Enter - for Sub
Enter * for Mul
Enter / for Div
Enter =>-
Output : 24)

16 ) Write a program where the user will enter the temperature and display a message
according to the temperature.
( Temp < 0 then freezing Atmosphere
Temp 0 to 10 then very cold atmosphere
Temp 10 to 20 then Cold Atmosphere
Temp 20 to 30 then normal Atmosphere
Temp 30 to 40 then hot atmosphere
Temp Greater than 40 then very hot atmosphere )

17 ) Write a program to see if the entered letter is a vowel or a consonant


(a is a vowel, h is a consonant )

18 ) Write a program to see if the entered letter is in upper case or lower case.
(a is in lowercase, A is in Uppercase)

18 ) Write a program where a user enters buying price and selling price then the output
should show if the person has made profit or loss
( buy = 400, Sell = 600, The User has made profit )

19 ) Write a Program where the user can enter any number between 1 to 9 and the
output should be the written word of the number.
( User enters 1 = One, 2 = Two )

www.Shyamsir.com

You might also like