Start Python Challenge: Day 1 Key Activities


Print in python
The
print()
function is used to display output on the screen.
print("Hello World")
Variables
A variable is used to store data that can be used later in a program. In Python, you don’t need to declare the type — it’s dynamically assigned.
name = "shiva"
x = 25
price = 24.78
Types of Operator
Python supports several types of operators:
Arithmetic Operators:
+
,-
,*
,/
,//
,%
,**
Assignment Operators:
=
,+=
,-=
,*=
,/=
,//=
,%=
,**=
Comparison Operators:
==
,!=
,>
,<
,>=
,<=
Logical Operators:
and
,or
,not
Bitwise Operators:
&
,|
,^
,~
,<<
,>>
Membership Operators:
in
,not in
Identity Operators:
is
,is not
Types Conversion
1. Implicit Conversion
Python automatically converts one data type to another.
a = 5 # int
b = 2.0 # float
result = a + b # result is float (7.0)
2. Explicit Conversion (Type Casting)
You manually convert one data type to another using built-in functions:
# int to float
x = float(5) # 5.0
# float to int
y = int(3.8) # 3
# string to int
z = int("10") # 10
# int to string
s = str(25) # "25"
Input in Python
a = input("what's the value of a?") #result of input is always str
b = int(input()) #result of input is integer
c = float(input()) #result of input in float
Let’s Practice
Q1: Write a program to input 2 numbers & print their sum
num1 = int(input("Enter the first input"))
num2 = int(input("Enter the second input"))
print(num1 + num2)
Q2: Write a program to input 2 floating point numbers & print their average
a = float("what's the a?")
b = float("what's the b?")
avg = (a + b)/ 2
print("average", avg)
Subscribe to my newsletter
Read articles from Shiva directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Shiva
Shiva
A self taught data scientist