You are on page 1of 4

Python Learning

Import math
pi = 3.14
x = 1
y = 2
z = 3
# print(round(pi))- rounding off
# print(math.ceil(pi))- upper value
# print(math.floor(pi))- lower value
# print(abs(pi))- absolute value
# print(pow(pi,2))- power raised to
# print(max(x,y,z))- maximum out of
three values
# print(max(x,y,z,pi))- minimum out of
three values
# print(math.sqrt(pi))- square root of
given value
#print(math.sqrt(34342))- square root
of any number
String Slicing
name = ("Mahadev Rokade")

first_name = name[0:8]-
index[start:end]
last_name = name[8:]- index[start:end]
reversed_name = name[::-1]-
index[start:end:step]
funky_name = name[::2]
print(first_name)
print(last_name)
print(reversed_name)
print(funky_name)

input function
name = input("what is your name:")
age = int(input("what is your age: "))
height = float(input("what is your
height: "))

print("hello"+name)
print("you are"+str(age)+"years old")
print(" and your height
is"+str(height))

slice option
website1 = "http://google.com"
website2 = "http://wikipedia.com"
slice = slice(7,-4)

print(website1[slice])
print(website2[slice])

if statements
age = int(input("How old are you? :"))

if age >= 18:


print("You're a adult now, boy/girl
congratulation")
elif age < 0:
print("You haven't born yet.")
elif age == 100:
print("You are century old")
else:
print("you are minor and child")

logical operators
and, or and not
temp = int(input("what is the
temperature today?: "))

if temp > 0 and temp < 30:


print("The weather is good today,
you can go outside")
elif temp < 0 or temp > 30:
print("The weather is not good
today, dont go outside")

Generally when the not used, it consider the entire


statement is false
temp = int(input("what is the
temperature today?: "))

if not(temp > 0 and temp < 30):


print("The weather is good today,
you can go outside")
elif not(temp < 0 or temp > 30):
print("The weather is not good
today, dont go outside")
While loops
name = ""

while len(name) == 0:
name = input(" what is your name:")
print (" hello "+str(name))

It will run until the condition is true

For loops = is the code which is run for the limited time
for i in range(50,100+1,2):
print(i)

for i in range(0,10):
print(i)

import time
for seconds in range (10,0,-1):
print(seconds)
time.sleep(1)
print("Happy New year")

You might also like