Python1
Python1
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
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
Hint print(“…
Hint print(“…
Hint a=5
print(“
Hint r=10
print(
Hint p=10000,r=2,n=2
print(
Hint H=100,B=200
print(
www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
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(…
Hint r=float(input(…
Hint meter=float(input(
print(“Centimetre =
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
11. Write a program to swap contents of the two variables without use of third variable
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
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
www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
www.Shyamsir.com
Shyamsir Python Language 78 74 39 11 91
• 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)
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)
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)
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 )
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