0% found this document useful (0 votes)
13 views

Python

Uploaded by

Nimesh Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Python

Uploaded by

Nimesh Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

varaible

any name assign value


a = "Hello World"
print(a)
variable rules:
1_ character user capital to capital in print
2_ d0 not use space between 2 word in varaible use number or _
3_can't start 1num error so use num1
@hello not work

Data types and userinput


text type :string
number type : int,floating,complex
sequence : list,tuple and range
mapping type: dictionaries
set type :set,forzenset
Boolean type :bool
Binary types: bytes,bytearray,memoryview

User input:
Input:
New website ask User name and password
NAME =input("Enter your name here: ")
print(NAME)
output:

strings means koi bhidata aav se Double "" ma


NAME =input("Enter your name here: ")
Int:
age=int(input("Enter age"))

Floating : Decimal ma number


lenth=float(input("Enter age"))
float can use 4 to 4.0

Evaluate :answer sodhi aap ne ex maths opeation/python ke regarding terms


exp1 = eval(input("enter any equvation here: "))
print (exp1)
Enter : 2+3 = 5
exp1 = eval(input("enter any equvation here: "))
print (exp1)
Enter : Hello World = Hello world print

Type casting and subtypes:


convert data type
1)Implcit type : convert by python
a= 123 # can't use " "
b= 1.23
print (type(a))
print (type(b))
c= a+b
print(c)
print(type(c)) ==> type show float
2)Explcit : user conver date to another data type
Ex 2:
a= "123"
b= 1.23
print (type(a))
print (type(b))
a= int(a)
print ("after conversation",type(a))
c= a+b
print(c)
print(type(c)) ==> type show int

Swap Temporary varaiable


First method :
x =12, Y =13
temp = x
print (temp)
x=y
print(x)
y= temp
print ("value of x is",x)
print ("value of x is",y)
===>Ans ; show x=13 and y =13
Second method above
x= 12
y =13

x,y = y,x
print (y)
print (x)
===>Ans ; show x=13 and y =13

1:08
Arithmatic Operation:
+,-,%,//,/,**,*

Comparisaon Opeators:
>,<,==,!=,>=,<=,

Logical operations:
and,or,not
and : bane condition true
or: bane mathi ek conditon
not : avaliable both -false aavase ==> result thi opoostie mate
print (not(3>4 and 5>7))

---1:26

assignment operators:
assign the value
game score 0
+=1 menas + j thasee
-=5 means - j thase
*=3 menas *

identidity operator:
is type
a=1234
b=1234
print(a is b)
answer true

is not type
a=1234
b=1234
print(a isnot b)
answer false

Bitweiser operator: used to compare the binary operator


And (&) operator
0 & 0=0
0 & 1 =0
1 & 0 =0
1 & 1 =1
1=on 0=off
print (bin(10))

a=10 b=8
print (a & b)
ans 8
OR:
0,0=0
1,0=1
0,1=1
1,1=1
a=10 b =8
print (a|b)
Ans 10
bitwise Xor operations:
0^0=0
1^0=1
0^1=1
1^1=0
a=10 b =8
print (a^b)
Ans 2
zero fill left shift : 10=1010 10>>>2 aagad ni be value add kar se pachad ni kadhi
nakh se
print (10>>1 )
answer 5
zero fill right shift :
10=1010
10<< 2 =40
print (10<<2 ) ans 40
membership operator
In Type:
a="hello"
print ("e" in a)
Ans true
1:47
conditional statments

if : varaible pass kiya ye condition satisfy or not kam karse nahitar next block ma
jase
marks=87
if marks >= 90;
print('you will get a mobile phone')
# scripts above blok 87 na case ma
print ("thank you")
Ans thank you

if else
bane mathi 1 condtion thasej
marks= 87
if marks>=90:
print ("youwill get mobile)
else:
print ("no phone")
Ans no phone

if elif else
multiple condtions last me ye karna he ya hoga
marks= 87
if marks>=90:
print ("youcan get gift")
elif marks>80 and marks<90:
print ("You will get a new phone")
elif marks>=70 and marks<80:
print ("you will get book")
else:
print ("no phone")
Ans you will get a new phone

nested if statements
--2:04
if ni adar if aave nestled
else last ma aapi finished karay jo if wadi na thay
Marks=87
if marks>=80:
pringt ("you will get phone")
if marks>=95:
print("willget iphone")
else:
print("No phone")

Short hand if statement


Marks=87
if marks>=90:print ("you will get phone")

Short if else:
Marks=87

print ("you will get phone") if marks>=90 else


print("No phone")

Problem Solving:
number postive or negative
num=(int(input("enter number: "))
if num >0:
print("it is postive")
else:
("it is negative")

ODd even check


num=(int(input("enter number: "))

if num % 2==0:
Print ("it is even")
else:
Print ("It is odd")
Create area calculator:
print("***area calcultor***")
print(""" press 1 to get the area of square
press 2 to ger area rectangle
press 3 to get circle
press 4 to get the area of triangle")
Choice=int(input("enter number 1 to 4: ")
if choice ==1:
side = float(input("enter the length of one side: "))
area= side**2
print("area of sware is",area)
elif_choice ==2:
length = float(input("enter length of retan: "))
width =float(input("enter the widethe of rec: *))
area=lenght* width
print ("the area of rectangle is " : ,area)
elif_choice =3;
radius= float(input("enter the radis circle: "))
2:28
area((22/7)*(radis**2))
print("the are of circle",area)
elif choice == 4;
base =_float(inpute(enter the tiangel:*00
height= floa
area=

You might also like