0% found this document useful (0 votes)
34 views8 pages

PYTHON FOR BEGINNERSada

The document is a comprehensive guide to Python programming, covering various topics such as data types, variables, input/output, string manipulation, operators, control flow statements, loops, and data structures like lists and tuples. It includes examples of arithmetic operations, logical conditions, and methods for manipulating strings and lists. Additionally, it explains concepts like operator precedence, type conversion, and the use of functions from the math module.

Uploaded by

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

PYTHON FOR BEGINNERSada

The document is a comprehensive guide to Python programming, covering various topics such as data types, variables, input/output, string manipulation, operators, control flow statements, loops, and data structures like lists and tuples. It includes examples of arithmetic operations, logical conditions, and methods for manipulating strings and lists. Additionally, it explains concepts like operator precedence, type conversion, and the use of functions from the math module.

Uploaded by

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

print("troy")

print('HAI' * 10) #hai is string '*' is multiplication operator 10 means hai will print 10 time

#variables r used to store data. ex A = 20 a is variable


price =100
print(price)

price =900
price =100
price = 2000
price =10000 #itb not like higher valve price 1st its print before value print
print(price)

#Integer is number without decimal point


price =150 #Integer
rating = 4.8 # float
movie_name ="amaran" #string
is_published =True # boolean
print('ticket priceis ',price,'movie rating ' ,rating,'movie name is ',movie_name,is_published)

#python is case senstivity language this means it distinguishes between uppercare abd
lowercase letters identifiers
NAME ="Troy"
name ="Arjun"
print(name)
print(NAME)
#print(name,NAME)

#Getting Input in puython you can get imnput from the use using the input() function ,its return
is as a string
name = input("what is your name: ")
#print (name)
#print('your name is: ',name) or
print('hai '+name) # '+' is concadonate to combain two string

#To Concatenate two strings i can use + operator ,this combines the string into a single string
First_name ='ARJUN'
last_name ='REDDY'
print(First_name + last_name)
print(First_name+""+last_name)

#Type conversion smaller dare types to larger data types


# there r two types 'Implicit (Automataic)' and 'Explicit(manual)'
rank = 10
rating =8.9
result = rank + rating #Automatic type conversion
print(result)

birth_year =input("Enter yout birth year: ")


age =2024- int (birth_year) #stirng to int manual conversion
print(age)

ibs = input("Enteryour lbs weight: ")


kg = int(ibs) *0.45 #manual type conversion
print(kg)

#STRING is a sequence of characters enclosed with single('),double("),triple(''') Quotes


name='TROY' #single(')
name="troy's bike name " #double(")
name='''my dog name is "Arjun" ''' #triple(''')
name=("python for begginners")
#012345 #-5-4-3-2-1
print(name[0])
print(name[:])#copy clone
print(name[-2]) #negative index
print(name[0:3])
print(name[0:])
print(name[:5])# 0 WILL start index
print(name[4:])

name=("python for begginners")


#012345 #-5-4-3-2-1
new_name =name[:] #copy clone
print(new_name)

name=("python for begginners")


print(name[2:-2])

#F-String (formatted string) i can embed expressions inside curly braces {} prefixed by the
letter f
fname ="troy"
lname="arjun"
#my name is [troy] my age is [25]
print('my name is ['+fname+'] My age is ['+lname+']') #it harder to visiulized

fname='arjun'
lname='reddy'
msg =f'my name is [{fname}] My age is [{lname}]' # F-String
print(msg)

#String methods python provides a wide range of build in methods to manipulate strings
#these methods operations like formatting searching splitting joining adb modifying strings

#common string methods


course = "python for beginners"
print(len(course)) #len()

#case conversion method


print(course.upper()) #upper() . operator for accessing function
print(course.lower()) #lower()
print(course.find('n')) #find() return index value of n is 5
print(course.replace('python','Absolute Python')) #replace()
print('python' in course) #in key word used to check if an element exist in a sequence its
produce boolean value

#Arithemetic operators
print(10/2) #return floating
print(10//2) #return integer value
print(10%2) #return remainder of the division
print(10**2) #exponent operator return power

#Augmented assignment operator


x=10
#x=x+3
x+=3 #Augmented assignment operator
print(x)

#Operator precedence determines the order in which operators are evaluated in expressions
#operators with higher precedence
# () parentheses highest
# ** Exponentiation
# +x,-x,~x uninary +,- and bitwise not
# or is lowest
x=10 + 6 * (5 * 3) + 2 ** 2 # x=(10 + 6) * 5 * 3
print(x)

#math function
x=2.9
print(round(x))
print(abs(-2.9)) #absulate always return positive

#math function
import math
print(math.ceil(1.2))

IF statement
'''
if its hot
its a hot day
drink plenty of water
otherwise if its cool day
its cold day
wear warm clothes
otherwise
its lovely day
'''
is_hot = False
is_cold = False
if is_hot:
print('its a hot day')
elif is_cold:
print("is cold day")
else:
print("ist lovely day")

price = 100
is_good_cridit= False
if is_good_cridit:
print("10%")
else:
print("20%")

#LOGICAL OPERATORS ARE USED to combine conditional statements


'''if applicant has high income AND good credit Eligible for loan'''
has_high_income = True
has_good_credit = False
if has_high_income and has_good_credit: #lOGICAL AND both condition is true
print("eligible for loan")
else:
print("not eligible for loan")

has_high_income = True #either of the condition is true


has_good_credit = False
if has_high_income or has_good_credit: #LOGICAL OR at least one condition is true
print("eligible for loan")
else:
print("not eligible for loan") # and not operators

'''Comparison operator are used to compare two values or variable'''


'''if temperature is greater than 30
its hot day
otherwise if its less than 30
its cold day
otherwise
its neither hot nor cold '''

temperature =59
if temperature>30: # ==,!+,>,>=
print("its hot day")
else:
print("its cold day")

'''If name is less han 3 characters long


name must be at least 3 characters
otherwise if its more than 50n charachers long
name can be a maximum of 50 characters
otherwise
name look good'''
name ="ARJUN SIVA SAM"
if len(name) < 3:
print("name muse be 3 char")
elif len(name) >20:
print("name cant be more than 20 char")
else:
print("good name")

weight =int(input("weight: "))


unit =input("k or L: ")
if unit.upper() == "L":
converted = weight * 0.45
print(f'YOUR KG IS {converted}')
else:
converted = weight // 0.45 #/ for floating point number
print("your lps is",converted)

'''A while loop is used to repeatedly execute a block of code as long


as a specified condition evaluates to True'''

glass =1
while glass<10:
print("filled",glass,"time")
glass=glass+1
print("finally filled the bucket")

secret_number = 9
i=0
limit = 3
while i< 3:
guess= int(input("guess: "))
i=i+1
if guess == secret_number:
print("U r won")
command = ("")
while command != "quit":
command = input(">") .lower()
if command == "start":
print("engine started...")
elif command == "stop":
print("engine is stopped...")
elif command == "help":
print('''start-start the engine
stop-stop the engine
quit-end the ganme''')
elif command == 'quit':
print("game ended")
break
else:
print("idiot type again!!!!")

'''forloop in python is used to iterate over a sequence and execute a block of code
for each element in that sequence ex list string and range'''
for item in "python":
print(item)

for names in ['ajay','potti','troy','aswin','me']: #list ['apple','orange','etc']


print(names)

'''for numbers in [1,2,3,4,5,6,'etc']:


print(numbers)'''
for numbers in range(10): #Range function range (5,10)
print(numbers)
for numbers in range(0,10,2): #step 0 to 10 the if you put 10 after 2 its will be print 02468
print(numbers)

prices=[10,20,30]
totel = 0
for price in prices:
totel += price # totel = total + price
print(f'totel: {totel}')

'''Nested loops is a loop inside another loop '''


#using nested loop we can create coordinate like
'''(x,y)
(0,0)
(0,1)
(0,2)
(1,0)
(1,1)
(1,2)
(2,0)
(2,1)'''
for x in range(3):
for y in range(3): #inner loop
print('(',x,',',y,')')

#output
'''( 0 , 0 )
( 0 , 1 )
( 0 , 2 )
( 1 , 0 )
( 1 , 1 )
( 1 , 2 )
( 2 , 0 )
( 2 , 1 )
( 2 , 2 )'''

f = [5,2,5,2,2]
for F in f:
print('x'* F)
u =[1,1,1,1,3]
for U in u:
print('x'* U)

#list is a data structure that allows you to store a collection of item in a single variable
names = ['troy','potti','arjun','viswa']
print(names[1])
print(names[0])
print(names[2:]) #index of string
print(names[-1])
print(names[1:3])
print(names[:])

numbers = [1,23,45,6,122]
ma= numbers[0]
for number in numbers:
if number > ma:
ma = number
print(ma)

#SD list in python is a list of lists


#In math we have a concept called matrix which is like a rectangle arry of numbers
'''[
123
456
789 3X3 matrix
]'''
matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
]
#matrix [0][1]=20
print(matrix[0][1])
for row in matrix:
for item in row:
print(item)

#List methods these are operations you can directly call on a list object
numbers=[1,3,9,12,3,3,3,3]
numbers.append(14) #append() add a element to end of the list
numbers.insert(0,0) #add index of the value
numbers.remove(12)
#numbers.clear() remove all element from the list
numbers.pop() #remove last(negative) value from index
print(numbers.index(3)) #return index of value if you enter value that doesnt exist in the list it
return error
print(numbers)
print(3 in numbers) #in operator return boolean value here ture or false this expression does
not give error safe to use
print(numbers.count(3)) #its count how many 3 in the list
#print(numbers.sort())
numbers.sort()
numbers.reverse() #desendind order
print(numbers)
numbers2 =numbers.copy()
numbers.append(100)
print(numbers)
print(numbers2) # copy()

#find unique numbers in list


numbers =[1,2,2,3,3,5,6,8]
uniques =[]
for number in numbers:
if number not in uniques:
uniques.append(number)
print(uniques)

#Tuples in python is an immutable(you cannot modify a tuple after creation)


'''numbers = [1,2,3] is list
numbers = (1,2,3) is tuples'''
numbers =(1,2,3)
#numbers[0]= 10
print(numbers[0])

#unpacking in Python refers to assigning elements of an iterable like (string ,list,tuples)


coordiantes = (1,2,3) #tuples
coordiantes = [1,2,3] #list
#coordiantes = ('a','b','c') string
'''x=coordinates[0]
y=coordinates[1]
z=coordinates[2] but we can'''
x,y,z = coordiantes
print(x)
print(y)
print(x,y,z)
#so this is unpacking

You might also like