0% found this document useful (0 votes)
3 views6 pages

Python Basics: Functions & Operations

This document contains Python programming notes covering various basic operations such as printing, arithmetic calculations, conditional statements, loops, string manipulations, and list operations. Each section includes code snippets demonstrating how to perform tasks like addition, subtraction, finding the largest or smallest number, generating Fibonacci series, and manipulating strings and lists. The notes serve as a quick reference for fundamental Python programming concepts and syntax.

Uploaded by

kaharvishakha2
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)
3 views6 pages

Python Basics: Functions & Operations

This document contains Python programming notes covering various basic operations such as printing, arithmetic calculations, conditional statements, loops, string manipulations, and list operations. Each section includes code snippets demonstrating how to perform tasks like addition, subtraction, finding the largest or smallest number, generating Fibonacci series, and manipulating strings and lists. The notes serve as a quick reference for fundamental Python programming concepts and syntax.

Uploaded by

kaharvishakha2
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

Python notes:-

1. print hello
print ("hello\n Good morning")

2. Add of number
a= int (input("enter the number"))
b= int (input("enter the number"))
add= a+b
print(add)

3. sub of number

a= int (input("enter the number"))


b= int (input("enter the number"))
sub= a-b
print(add)

4. mul of number

a= int (input("enter the number"))


b= int (input("enter the number"))
add= a*b
print(add)

5. div of a number

a= int (input("enter the number"))


b= int (input("enter the number"))
mul= a/ b
print(mul)

6. Swap a number

a= int (input("enter the number"))


b= int (input("enter the number"))
temp=a
a=b
temp=b
print("x",a,"y",b)
#method 2

a,b=b,a
8. Area of square
a= int (input("enter the number"))
square= 4*a
print(square)

9. Area of rectangle

a= int (input("enter the number"))


b= int (input("enter the number"))
rec = a*b
print(rec)

10. square of a number


a= int (input("enter the number"))
square = a*a
print("square is :-",square)

11. cube of a number.


a= int (input("enter the number"))
#= int (input("enter the number"))
cube = a*a*a
print("cube is :-",cube)

12 . Celsius to fahrenheit.
c= float (input("enter the number"))
F= (c*9/5)+32
print ("this celsius is :",F)

Conditional
statement :
[Link] OR ODD
n= int(input("enter the number "))
if (n%2==0):
print ("EVEN BABE ")
else:
print("OH ODD BABE ")
14. LARGEST NUMBER
a= int(input("enter the number "))
b= int(input("enter the number "))
if a>b:
print ("LARGEST ",a)
else:
print("largest",b)

15. SMALLEST OF NUMBER


a= int(input("enter the number "))
b= int(input("enter the number "))
if a<b:
print ("SMALLEST ",a)
else:
print("SMALLEST",b)

16. LARGEST IN INPUT


a,b,c,d=(12,45,6,78)
print("largest value is ",max(a,b,c,d))

17. SMALLEST IN INPUT


a,b,c,d=(12,45,6,78)
print("largest value is ",max(a,b,c,d))

18. GREATER AND SMALLEST


v=int(input("enter a number"))
k= int(input("enter a number"))
if(v>k):
print ("greather than",v)
else:
print ("greaterr than ",k)
if (v<k):
print("smallest",v)
else:
print("smaller",k)

LOOPING
STATEMENTS:---
19. FACTORIAL OF A NUMBER
n=int(input("enter a number"))
fact=1
for i in range(1,n+1):
fact *=i
print(fact)

20. FABONACCI SERIES


n=int(input("enter a number"))
p=int(input("enter a number"))
for _ in range(10):
print(n,end=" ")
n , p=p , n+p

# Method:2
n,p=0,1
for _ in range(10):
print(n,end=" ")
n,p=p,n+p

21. MULTIPILICATION OF TABLE


n=int(input("enter a table number "))
for i in range (1,11):
print(n,"x",i,"=",n*i)

22. SUM OF AN NATURAL NUM:


n=int(input("enter a number "))
print(sum(range(1,n+1)))

23. REVERSE OF A NUMBER


n=int(input("enter a number "))
for i in range (n ,0, -1):
print(i,end=" \n ")

24. N NUM OF EVEN


n=int(input("enter a number "))
for i in range ( 2 ,n, 2):
print(i,end="\n")

25. N NUM ODD


n=int(input("enter a number "))
for i in range ( 1 ,n, 2):
print(i,end="\n")

26. PRIME NUMBER


n=int (input("enter a number "))
for n in range(2,n):
if all (n%i !=0 for i in range (2,int(n**0.5)+1)):
print(n,end=" ")
27. COUNT OF NUMBER
n=int (input("enter a number "))
print(len(str(n)))

28. REVERSEOF A NUMBER


n=int (input("enter a number "))
print(str(n)[:: -1])

STRING:-
29. REVERSE OF STRING
n=str (input("enter a string "))
print(n[:: -1])

30. PALINDROME CHECK


n=str (input("enter a string "))
print( "YES "if n==n[:: -1] else "NO")

31. COUNT VOWEL


s=str (input("enter a string "))
print( sum(1 for ch in s if [Link]() in "aeiou"))

32. LENGTH OF STRING


s=str (input("enter a string "))
print(len(s))

33. UPPER CASE


s=str (input("enter a string "))
print([Link]())

34. LOWER CASE


v=str (input("enter a string "))
print([Link]())

35. CAPITALIZE CASE


k=str (input("enter a string "))
print([Link]())

36. COUNTS WORD IN SEN


s=str (input("enter a string "))
print(len([Link]()))

37. REPLACE SUBSTRING


s=str (input("enter a string "))
print([Link](" YOU", " python"))
38. FIND SUBSTRING
s="programming"
print(" gram" in s )

40. REMOVE SPACE


s=str (input("enter a string "))
print ([Link](" ",""))

LISTS:-
41. LARGEST ELEMENT
list=[1,3,4,6,8,9,34,]
print("the maximum element is :",max(list))

42. SMALLEST ELEMENT


list=[1,3,4,6,8,9,34,]
print("the minimum element is :",min(list))

43. SUM OF LIST


list=[1,3,4,6,8,9,34,]
print ("the sum of element is :",sum(list))

44. SORT LIST


list=[1,13,4,64,9,34,]
[Link]()
print ((list))

[Link] LIST
list=[1,13,4,64,9,34,]
[Link]()
print ((list))

[Link] DUPLICATE
lst=[1,1,4,64,9,34,9,6,]
print (list(set(lst)))

47.

You might also like