Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Python Notes

07/04/2020

IDE – Integrated development Environment

PyCharm Tip: 1

You can use the Preview area of the Find in Path dialog (Ctrl+Shift+F) for quicker
search without leaving the dialog. The Preview dialog displays the first 100
results.

PyCharm Tip: 2

Press Ctrl+Shift+F7 (Edit | Find | Highlight Usages in File) to quickly highlight


usages of a certain variable in the current file.

Press F3 and Shift+F3 to navigate through the highlighted usages.

Press Escape to remove highlighting.

Print function
Syntax: print(“hello world”)

1
10/07/2020

 Program 2 - Strings

person_name ="Mrs.Athira"
object_1 = "car"
object_1_color = "red"
object_2 = "home"
object_2_age = "20 years old"

print("Hello," +person_name)
print("i am very interested in your " +object_1,"if its
" +object_1_color)
print("also interested in " +object_2,"it is "
+object_2_age)
print("Thank you "+person_name)

Output

Hello,Mrs.Athira

i am very interested in your car if its red

also interested in home it is 20 years old

Thank you Mrs.Athira

Process finished with exit code 0

2
 Program 3 - Strings Manipuilation

sentence="I love pizza"


print(sentence)

Output

I love pizza

 Program 4 - Strings Manipuilation


o upper
sentence="I love pizza"
print(sentence.upper())

I LOVE PIZZA

Note: To make upper case write upper()

o lower

 sentence="I love pizza"


print(sentence.lower())

o islower

To check all the characters are in lower put .islower()

Syntax
sentence="I love pizza"
print(sentence.islower())

3
o length of a sentence

sentence="I loVe pizza"


print(len(sentence))

o replace word in a sentence

sentence="I loVe pizza and love to eat with pepsi full


of ice"
print(sentence.replace("pizza","burger"))

Output
I loVe burger and love to eat with pepsi full of ice

o Find position of letter / word in a sentence

sentence="I loVe pizza and love to eat with pepsi full


of ice"
print(sentence.index("e"))

output
5

Note:python will start counting with 0, so in this


example python count I as 0th letter and ‘e’ as 5th
letter.

4
o To separate sentence (“ \n “)

print("I loVe pizza\nand \nlove to eat with pepsi \


nfull of ice")

Output

I loVe pizza

and

love to eat with pepsi

full of ice

5
11/07/2020

Numbers

from math import *


age=25+40

print("my age is " +str(age))

output
my age is 65

6
12/07/2020

 Program 6 - Input functions

name=input("what is your name")


gender=input("what is your gender")
age=input("what is your age")

print("my name is "+name+ " and am a " +gender+" and am


" +age +" year old" )

Output

what is your name Gibin


what is your gender male
what is your age 32
my name is Gibin and am a male and am 32 year old

7
 Test program – 1

price_product_1=input("what is the price of product 1")


quantity_product_1=input("what will be the quantity of
product 1")
price_product_2=input("what is the price of product 2")
quantity_product_2=input("what will be the quantity of
product 2")
price_product_3=input("what is the price of product 3")
quantity_product_3=input("what will be the quantity of
product 3")

result_product_1=float (price_product_1 )* float


(quantity_product_1)
result_product_2=float (price_product_2 )* float
(quantity_product_1)
result_product_3=float (price_product_1 )* float
(quantity_product_1)

result=
result_product_1+result_product_2+result_product_3

print("total cost is "+str(result)+"rs")

8
output

what is the price of product 120


what will be the quantity of product 12
what is the price of product 220
what will be the quantity of product 22
what is the price of product 320
what will be the quantity of product 32
total cost is 120.0rs

9
 Test program – 2

name_1=input("What is your name: ")


name_2=input("What is your name: ")
name_3=input("What is your name: ")

price_of_pizza=input("Whats the prize of pizza: ")


Number_of_slice=input("How many slice in pizza: ")

Number_of_slice_eat_by_name_1=input("Number of slices
eat by "+name_1)
Number_of_slice_eat_by_name_2=input("Number of slices
eat by "+name_2)
Number_of_slice_eat_by_name_3=input("Number of slices
eat by "+name_3)

Price_for_1_slice= float(price_of_pizza)/
float(Number_of_slice)

price_paid_by_name_1=
float(Number_of_slice_eat_by_name_1)*float(Price_for_1_
slice)
price_paid_by_name_2=
float(Number_of_slice_eat_by_name_2)*float(Price_for_1_
slice)
price_paid_by_name_3=
float(Number_of_slice_eat_by_name_3)*float(Price_for_1_
slice)

print(name_1+ " eats "


+str(Number_of_slice_eat_by_name_1)+" numbers of
slices"+"Total amount paid will be
"+str(price_paid_by_name_1)+"Rs")
print(name_2+ " eats "

10
+str(Number_of_slice_eat_by_name_2)+" numbers of
slices"+"Total amount paid will be
"+str(price_paid_by_name_2)+"Rs")
print(name_3+ " eats "
+str(Number_of_slice_eat_by_name_3)+" numbers of
slices"+"Total amount paid will be
"+str(price_paid_by_name_3)+"Rs")

Output

What is your name: ANJU

What is your name: ANU

What is your name: REENU

Whats the prize of pizza: 750

How many slice in pizza: 8

Number of slices eat by ANJU 3

Number of slices eat by ANU 4

Number of slices eat by REENU 1

ANJU eats 3 numbers of slicesTotal amount paid will be 281.25Rs

ANU eats 4 numbers of slicesTotal amount paid will be 375.0Rs

REENU eats 1 numbers of slicesTotal amount paid will be 93.75Rs

11
 Function-def

def per1_1 (name):


print(name+":Hello, How can i help you")
def per2_1(name,food,drink,dessert):
name=input("what is your name: ")
food=input("what do you want to eat: ")
drink=input("what do you want to drink: ")
dessert=input("what dessert you want to take: ")
print(name+": i would like to eat "+food+"along
with "+drink+"and after i will have "+dessert)

def per1_2(name):
print(name+ ":Thank you ")

per1_1("cashier")
per2_1("name","food","drink","dessert")
per1_2("cashier")

Output

cashier:Hello, How can i help you


what is your name: Gibin
what do you want to eat: Pizza
what do you want to drink: COke
what dessert you want to take: Cake
Gibin: i would like to eat Pizzaalong with COkeand
after i will have Cake
cashier:Thank you

12
15/07/2020

 BOOLEAN – 1

i_wanna_watch_netflix=False
i_wanna_watch_prime=False

if i_wanna_watch_netflix:
print(" watch moneyheist ")
elif i_wanna_watch_prime:
print("watch paatallok")
else:print("lets sleep")

 BOOLEAN – 2

per1_name=input("whats your name: ")


per1_wallet=input("How much money you have in Rs: ")

per2_name=input("whats your name: ")


per2_wallet=input("How much money you have in Rs: ")

per3_name=input("whats your name: ")


per3_wallet=input("How much money you have in Rs: ")

if float(per1_wallet)>float(per2_wallet) and
float(per1_wallet)>float(per3_wallet):
print(per1_name+ " is the richest one ")

elif float(per2_wallet)>float(per1_wallet) and


float(per2_wallet)>float(per3_wallet):
print(per2_name+ " is the richest one ")

elif float(per3_wallet) > float(per2_wallet) and


float(per3_wallet) > float(per1_wallet):
print(per3_name + " is the richest one ")

13
OUTPUT

whats your name: appu


How much money you have in Rs: 10
whats your name: dippu
How much money you have in Rs: 5
whats your name: doppu
How much money you have in Rs: 6
appu is the richest one

14
 Encryption

def crypted (sentence):


translation = ""
for element in sentence:
if element in "Aa":
translation=translation+"1"
elif element in "Bb":
translation=translation+"2"
elif element in "Cc":
translation = translation + "3"
elif element in "Dd":
translation = translation + "4"
elif element in "Ee":
translation = translation + "5"
elif element in "Ff":
translation = translation + "6"
elif element in "Gg":
translation = translation + "7"
elif element in "Hh":
translation=translation+"8"
elif element in "Ii":
translation=translation+"9"
elif element in "Jj":
translation=translation+"0"
elif element in "Kk":
translation=translation+"@"
elif element in "Ll":
translation=translation+"#"
elif element in "Mm":

translation=translation+"$"
elif element in "Nn":
translation=translation+"%"
elif element in "Oo":
translation=translation+"^"
elif element in "Pp":
translation=translation+"&"
elif element in "Qq":
15
translation=translation+"*"
elif element in "Rr":
translation=translation+"1"
elif element in "Ss":
translation=translation+"("
elif element in "Tt":
translation=translation+")"
elif element in "Uu":
translation=translation+"_"
elif element in "Vv":
translation=translation+"-"
elif element in "Ww":
translation=translation+"="
elif element in "Xx":
translation=translation+"+"
elif element in "Yy":
translation=translation+"["
elif element in "Zz":
translation=translation+"]"
else:
translation=translation+element
return translation
print(crypted(input("Whats your word to encrypt : ")))

16

You might also like