Python for Kids
Lecture-3
Input & Operators
Agenda
• About our Groups and Heads
• Data Types
• Input() function
• Operators
Group-A
Class : 3rd and 4th
Students : 49
Heads :
1. Gurutej Singh
2. Kavya
Group-B
Class : 5th
Students : 62
Heads :
1. Geetansh 2. Vaibhav
Group-C
Class : 6th
Students : 52
Heads :
1. Kashinadh 2. Vivaan Goel
Group-D
Class : 7th and 8th
Students : 54
Heads :
1. Sanvi 2. Ayush Lokhande
Data types
• aa
Input() Functions
Syntax:
var = input(“Message”)
Note : it return a string
name = input(“enter your name:”)
print(“\n Hello ”,name)
OUTPUT
Enter your name:
Amit
Hello Amit
Input integer number
a = input(“enter any number:”) a = int(input(“enter any number:”))
b=int(a) print(“\n Predecessor = ”,a-1)
print(“\n Predecessor = ”,b-1)
OUTPUT OUTPUT
Enter any number: Enter any number:
12 12
Predecessor = 11 Predecessor = 11
Input floating number
a = input(“enter any number:”) a = float(input(“enter any number:”))
b=float(a) print(“\n Predecessor = ”,a-1)
print(“\n Predecessor = ”,b-1)
OUTPUT OUTPUT
Enter any number: Enter any number:
12.5 12.5
Predecessor = 11.5 Predecessor = 11.5
Operators
In python there are following operators:
1. Arithmetic Operators
2. Assignment Operators
3. Relational Operators
4. Logical Operators
5. Bitwise Operators
6. Identity Operators
Note : Increment/decrement (Missing in Python)
+ Addition
Arithmetic Operators
>>>55+45 >>> “Good‟ + “Morning‟
100 GoodMorning
- Subtraction A= 10, B=2
>>>55-45 10
* Multiplication C=A%B
>>>55*45 >>> “Good”* 3
2475 GoodGoodGood
C=0 EVEN
/ Division A= 31, B=2
>>>17/5 3.4
% Remainder/ Modulo C=A%B
>>>17%5 2
** Exponentiation C=1 ODD
>>>2**3 >>>16**.5 A= 143,B=10
8 4.0
// Integer Division C=A%B
>>>7//2 >>>3/ / 2
3 1 C=3 LAST DIGIT
=, Assignment Operators
+=,
-=,
*=,
/=, /
/=,
%=,
**=
Assignment Operators
= , +=, -=, *=, /=, %=, //=, **=
A= 10 A= 10, B=20 A= 11, B=5
B=20 A+=B A//=B
A=30 A=2
A= 10, B=5 A= 10, B=5 A= 10, B=2
A-=B A*=B A**=B
A=5 A=50 A=100
A= 11, B=5 A= 10, B=2
A/=B C=A%B
A=2.2 C=0
Relational Operators
<, <=, >, >=, !=, ==
Relational Operators
<, <=, >, >=, !=, ==
Symbols A=5, B=10 A=10, B=5 A=10, B=10
A<B True False False
A<=B True False True
A>B False True False
A>=B False True True
A==B False False True
A!=B True True False
Logical Operators
and logical and
or logical or
not logical not
Logical Operators
and, or , not
C1 C2 C1 and C2 C1 or C2 not C1
True True True True False
True False False True False
False True False True True
False False False False True
Bitwise Operators
&
|
~
^
<<
>>
in
Identity Operators
is
>>> a=5
>>> b=5
>>> a is b
True
>>> b is a
True
>>> b is not a
False
>>> a="welcome"
>>> b="wel"
>>> b in a
True
>>> a in b
False
1. Display the last digit of any input of number.
2. Write a program to display the addition, multiplication, subtraction and division of two input
numbers.
3. Write a program to display the addition, multiplication, subtraction and division of two input floats.
4. Write a program to display value of x for given variable a, b and c in given equation:
5. Write a program to input a distance in meter and display in kilometers.
6. Write a program to input a distance in Kilometer and display in meters.
7. Write a program to input an amount in paisa and display in rupees.
8. Write a program to input an amount in Rupees and display in paisa.
9. Write a program to input a temperature in Fahrenheit and display in Celsius. [Formula: C=5/9×(F-32)]
10. Input two numbers swap their values and display before swapping & after swapping.
11. Input two numbers swap their values without using third variable and display them.
12. Input an amount in rupees and display the quantity of 2000 currency notes and show remaining
amount: input: 4065, output: 2000 notes=2 , remaining amount= 65
13. Input an amount in rupees and display the quantity of each currency notes, For Example: Input
amount: 4065 , Output: 2000 : 1 notes
1000 : 0 note
500 : 0 note
50 : 1 note
10 : 1 note
ASSIGNMENTS 5 : 1 note