├── 01. Print numbers from 1 to 10.py
├── .idea
├── .gitignore
├── vcs.xml
├── inspectionProfiles
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── Python Programs.iml
├── .gitattributes
├── 17. Read from a file.py
├── 16. Write to a file.py
├── 19. Count lines in a file.py
├── Find Multiple of 3 in List.py
├── 02. Sum of all even numbers from 1 to 100.py
├── 18. Append data to a file.py
├── 05. Fibonacci series up to 10 terms.py
├── 11. Handle division by zero.py
├── Marks.txt
├── Square Root.py
├── 04. Print multiplication table for a given number.py
├── Celsius to Fahrenheit.py
├── Fahrenheit to Celsius.py
├── Even or Odd.py
├── Find leap year.py
├── Leap Year.py
├── 09. Check if a year is a leap year.py
├── 15. Finally block usage.py
├── 07. Check if a number is even or odd.py
├── Multiplication Table.py
├── Recursive Factorial.py
├── 12. Handle file not found error.py
├── 06. Check if a number is positive, negative, or zero.py
├── Age Checker.py
├── README.md
├── Find the age category.py
├── Find the marks category.py
├── Palindrome.py
├── Recursive Fibonacci.py
├── 08. Find the largest of three numbers.py
├── Vowel or Consonant in a String.py
├── 03. Reverse a string using a loop.py
├── 10. Menu-driven calculator program.py
├── Find the Number of Vowels and Consonant in a String.py
├── Calculator Using Match Case.py
├── 13. Raise a custom exception.py
├── 14. Handle multiple exceptions.py
└── Marks Using File IO operations.py
/01. Print numbers from 1 to 10.py:
--------------------------------------------------------------------------------
1 | for i in range(1,11):
2 | print(i)
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/17. Read from a file.py:
--------------------------------------------------------------------------------
1 | with open("ABC.txt","r") as f:
2 | print(f.read())
3 |
--------------------------------------------------------------------------------
/16. Write to a file.py:
--------------------------------------------------------------------------------
1 | with open("ABC.txt","w") as f:
2 | f.write("Hello this is python!")
3 |
--------------------------------------------------------------------------------
/19. Count lines in a file.py:
--------------------------------------------------------------------------------
1 | with open("ABC.txt","r") as f:
2 | a=len(f.readlines())
3 | print(a)
--------------------------------------------------------------------------------
/Find Multiple of 3 in List.py:
--------------------------------------------------------------------------------
1 | j=[27,25,34,53,63,44,64,77,55,64]
2 | a=[i for i in j if i % 3 == 0]
3 | print(a)
--------------------------------------------------------------------------------
/02. Sum of all even numbers from 1 to 100.py:
--------------------------------------------------------------------------------
1 | a=0
2 | for i in range(2,101,2):
3 | a+=i
4 | print(a)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/18. Append data to a file.py:
--------------------------------------------------------------------------------
1 | with open("ABC.txt","a") as f:
2 | f.writelines("\n This is the right thing to do\n")
--------------------------------------------------------------------------------
/05. Fibonacci series up to 10 terms.py:
--------------------------------------------------------------------------------
1 | a=0
2 | b=1
3 | for i in range(1, 10):
4 | print(a, end=" ")
5 | a,b= b,b+a
--------------------------------------------------------------------------------
/11. Handle division by zero.py:
--------------------------------------------------------------------------------
1 | try:
2 | print(2/0)
3 | except ZeroDivisionError:
4 | print("Rolex is Expensive")
--------------------------------------------------------------------------------
/Marks.txt:
--------------------------------------------------------------------------------
1 | 15, 14, 15, 15, 12
2 | 14, 12, 14, 15, 11
3 | 15, 14, 15, 18, 16
4 | 08, 09, 14, 10, 11
5 | 20, 19, 18, 18, 19
--------------------------------------------------------------------------------
/Square Root.py:
--------------------------------------------------------------------------------
1 | import math
2 | a= int(input("Enter the number to find the Square root:- "))
3 | b= math.sqrt(a)
4 | print(b)
--------------------------------------------------------------------------------
/04. Print multiplication table for a given number.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter number:- "))
2 | for i in range(1,11):
3 | print(a,"*",i,"=",a*i)
--------------------------------------------------------------------------------
/Celsius to Fahrenheit.py:
--------------------------------------------------------------------------------
1 | a= int( input( "Enter the temperature in Celsius:- "))
2 | b=(a*9/5)+32
3 | print("Temperature is",b,"Degree Fahrenheit.")
--------------------------------------------------------------------------------
/Fahrenheit to Celsius.py:
--------------------------------------------------------------------------------
1 | a= int( input( "Enter the temperature in Fahrenheit:- "))
2 | b= (a-32)*5/9
3 | print("Temperatrue is",b,"Degree Celsius.")
--------------------------------------------------------------------------------
/Even or Odd.py:
--------------------------------------------------------------------------------
1 | a= int( input( "Enter the Number:- "))
2 | if(a%2== 0):
3 | print(a," is an Even Number.")
4 | else:
5 | print(a," is a Odd Number.")
--------------------------------------------------------------------------------
/Find leap year.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter the year:- "))
2 | if(a%4== 0):
3 | print(a," is a leap year.")
4 | else:
5 | print(a," is not a leap year.")
--------------------------------------------------------------------------------
/Leap Year.py:
--------------------------------------------------------------------------------
1 | # To Check Leap Year
2 | a=int(input("Enter the year:- "))
3 | if(a%4==0):
4 | print(a,"is Leap Year.")
5 | else:
6 | print(a,"is not leap Year.")
7 |
8 |
--------------------------------------------------------------------------------
/09. Check if a year is a leap year.py:
--------------------------------------------------------------------------------
1 | year = 184
2 | if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
3 | print("Leap year")
4 | else:
5 | print("Not a leap year")
6 |
--------------------------------------------------------------------------------
/15. Finally block usage.py:
--------------------------------------------------------------------------------
1 | try:
2 | a=int(input("Enter the number:- "))
3 | b=a/0
4 | except ZeroDivisionError:
5 | print("Wrong Input")
6 | finally:
7 | print("Work Done")
--------------------------------------------------------------------------------
/07. Check if a number is even or odd.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter the number: "))
2 | if(a%2== 0):
3 | print("even")
4 | else:
5 | print("odd")
6 |
7 |
8 | print("even"if a%2==0 else "odd")
--------------------------------------------------------------------------------
/Multiplication Table.py:
--------------------------------------------------------------------------------
1 | # Multiplication Table
2 | a=int(input("Enter the Multiplicand:- "))
3 | b=int(input("Enter the Multiplier:- "))
4 | for i in range(1,b+1):
5 | print(a,"*",i,"=",a*i)
--------------------------------------------------------------------------------
/Recursive Factorial.py:
--------------------------------------------------------------------------------
1 | def factorial(a):
2 | if(a==1 or a==0):
3 | return(1)
4 | return(a*factorial(a-1))
5 |
6 | x=int(input("Enter Number:- "))
7 | n=factorial(x)
8 | print(n)
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/12. Handle file not found error.py:
--------------------------------------------------------------------------------
1 | try:
2 | with open("Tranform.txt","r") as a:
3 | b= a.read()
4 | print(b)
5 | except FileNotFoundError:
6 | print("Valhalla is waiting for you.")
--------------------------------------------------------------------------------
/06. Check if a number is positive, negative, or zero.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter the number:- "))
2 | if(a>0):
3 | print("Positive Number")
4 | elif(a==0):
5 | print("Zero")
6 | else:
7 | print("Negative Number")
--------------------------------------------------------------------------------
/Age Checker.py:
--------------------------------------------------------------------------------
1 | # Age Checker
2 | a=int(input("Enter age:- "))
3 | if(a<12):
4 | print("Child")
5 | elif(a<18):
6 | print("Teenager")
7 | elif(a<60):
8 | print("Adult")
9 | else:
10 | print("Senior")
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python-Programs
2 | Python is a high-level, general-purpose programming language known for its readability and ease of use. It was created by Guido van Rossum in the late 1980s and released to the public in 1991.
3 |
--------------------------------------------------------------------------------
/Find the age category.py:
--------------------------------------------------------------------------------
1 | X= int( input( "Enter Age:- "))
2 | if( X>= 65):
3 | print("Senior")
4 | elif( X>= 20):
5 | print("Adult")
6 | elif( X>= 13):
7 | print("Teenager")
8 | else:
9 | print("Child")
10 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Find the marks category.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter Marks:- "))
2 | if(a>=90):
3 | print("A")
4 | elif(a>=80):
5 | print("B")
6 | elif(a>=70):
7 | print("C")
8 | elif(a>=60):
9 | print("D")
10 | elif(a>=50):
11 | print("E")
12 | else:
13 | print("F")
--------------------------------------------------------------------------------
/Palindrome.py:
--------------------------------------------------------------------------------
1 | # Palindrome
2 | a=input("Enter the String:- ")
3 | b=0
4 | for i in range (len(a)//2):
5 | if(a[i]!=a[-i-1]):
6 | b=1
7 | break
8 | if(b==0):
9 | print(a, "is Palindrome.")
10 | else:
11 | print(a, "is not Palindrome.")
12 |
--------------------------------------------------------------------------------
/Recursive Fibonacci.py:
--------------------------------------------------------------------------------
1 | # Fibonacci Series Using Recursion
2 | def fibonacci(a):
3 | if(a==0):
4 | return(0)
5 | if (a==1):
6 | return(1)
7 | return(fibonacci(a-1)+fibonacci(a-2))
8 |
9 | x= int(input("Enter number:- "))
10 | n=fibonacci(x)
11 | print(n)
--------------------------------------------------------------------------------
/08. Find the largest of three numbers.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter first number:- "))
2 | b= int(input("Enter second number:- "))
3 | c= int(input("Enter third number:- "))
4 |
5 | print(max(a,b,c))
6 |
7 | if(a>b and a>c):
8 | print(a)
9 | elif(b>c):
10 | print(b)
11 | else:
12 | print(c)
13 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Vowel or Consonant in a String.py:
--------------------------------------------------------------------------------
1 | a= input(" Enter the String:- ")
2 |
3 | b=len(a)
4 |
5 | for i in range(0,b):
6 | if(a[i]== "a" or a[i]== "e" or a[i]== "i" or a[i]== "o" or a[i]== "u" or a[i]== "A" or a[i]== "E" or a[i]== "I" or a[i]== "O" or a[i]== "U"):
7 | print(a[i]," is vowel.")
8 | else:
9 | print(a[i]," is consonant.")
--------------------------------------------------------------------------------
/.idea/Python Programs.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/03. Reverse a string using a loop.py:
--------------------------------------------------------------------------------
1 | a="Termination"
2 | c=""
3 | for i in range(len(a),0,-1):
4 | c=c+a[i-1]
5 |
6 | print(c)
7 |
8 |
9 |
10 |
11 | text = "Python"
12 | reversed_text = ""
13 | for char in text:
14 | reversed_text = char + reversed_text
15 | print("Reversed:", reversed_text)
16 |
17 |
18 |
19 |
20 | a= "retard"
21 | b= ""
22 | for i in a:
23 | b= i+b
24 | print(b)
--------------------------------------------------------------------------------
/10. Menu-driven calculator program.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter First number:- "))
2 | b= int(input("Enter Second number:- "))
3 | c= input("Choose Add, Sub, Mul, Div:- ")
4 |
5 | match c:
6 | case "Add":
7 | print(a+b)
8 | case "Sub":
9 | print(a-b)
10 | case "Mul":
11 | print(a*b)
12 | case "Div":
13 | print(a/b)
14 | case _:
15 | print("Option not available")
--------------------------------------------------------------------------------
/Find the Number of Vowels and Consonant in a String.py:
--------------------------------------------------------------------------------
1 | a= input(" Enter the String:- ")
2 | b=len(a)
3 | v=0
4 | c=0
5 |
6 | for i in range(0,b):
7 | if(a[i]== "a" or a[i]== "e" or a[i]== "i" or a[i]== "o" or a[i]== "u" or a[i]== "A" or a[i]== "E" or a[i]== "I" or a[i]== "O" or a[i]== "U"):
8 | v+=1
9 | else:
10 | c+=1
11 |
12 | print("There are ",v,"Vowels and there are ",c,"Consonants")
--------------------------------------------------------------------------------
/Calculator Using Match Case.py:
--------------------------------------------------------------------------------
1 | a= int(input("Enter first number:- "))
2 | b= int(input("Enter Second number:- "))
3 | c= input("Enter the Operation to be performed:- ")
4 |
5 | match c:
6 | case "Addition":
7 | print(a+b)
8 | case "Subtraction":
9 | print(a-b)
10 | case "Multiplication":
11 | print(a*b)
12 | case "Division":
13 | print(a/b)
14 | case _:
15 | print("No Valid Operation Provided.")
16 |
--------------------------------------------------------------------------------
/13. Raise a custom exception.py:
--------------------------------------------------------------------------------
1 | class Cstm(Exception):
2 | pass
3 |
4 |
5 |
6 |
7 |
8 |
9 | try:
10 | a=int(input("Enter 2:- "))
11 | if(a==2):
12 | raise Cstm("You Entered 2!")
13 | else:
14 | print("Smart Choice")
15 | except Cstm:
16 | print("Custom Exception")
17 |
18 |
19 |
20 | class NegativeNumberError(Exception):
21 | pass
22 |
23 | num = -1
24 | if num < 0:
25 | raise NegativeNumberError("Negative number not allowed.")
26 |
--------------------------------------------------------------------------------
/14. Handle multiple exceptions.py:
--------------------------------------------------------------------------------
1 | try:
2 | x=int(input("Enter Number:- "))
3 | print(2/x)
4 | except ZeroDivisionError:
5 | print("This is ZeroDivisionError")
6 | except ValueError:
7 | print("This is ValueError")
8 | except Exception as a:
9 | print("Program not running because of:", a)
10 |
11 |
12 |
13 | try:
14 | num = int(input("Enter a number: "))
15 | print(f"Square of {num} is {num ** 2}")
16 | except ValueError:
17 | print("Error: Input must be a valid integer.")
18 | else:
19 | print("Program executed successfully.")
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Marks Using File IO operations.py:
--------------------------------------------------------------------------------
1 | a= open("Marks.txt","r")
2 | i=1
3 | while True:
4 | x=a.readline()
5 | print(x)
6 | if not x:
7 | break
8 | y1= int(x.split(",")[0])
9 | y2= int(x.split(",")[1])
10 | y3= int(x.split(",")[2])
11 | y4= int(x.split(",")[3])
12 | y5= int(x.split(",")[4])
13 | print(f"Marks of Physics of Student{i}= {y1}")
14 | print(f"Marks of Physics of Student{i}= {y2}")
15 | print(f"Marks of Physics of Student{i}= {y3}")
16 | print(f"Marks of Physics of Student{i}= {y4}")
17 | print(f"Marks of Physics of Student{i}= {y5}")
18 | i+=1
19 | a.close()
--------------------------------------------------------------------------------