Class XII python practical file should have 20 python programs and 5 SQL Queries.
- Basic general programs
- if condition based programs
- loop based programs
- function based programs
- function with recursion programs
- python with numpy programs
- python and MySQL connectivity programs
- SQL Queries
Programs:
Question:1
Write a python script to take input for a number calculate and print its square and cube?
a=int(input("Enter any no ")) b=a*a c=a*a*a print("Square = ",b) print("cube = ",c)
Output:
Enter any no 10
Square = 100
cube = 1000
>>>
Question:2
Write a python script to take input for 2 numbers calculate and print their sum, product and difference?
a=int(input("Enter 1st no ")) b=int(input("Enter 2nd no ")) s=a+b p=a*b if(a>b): d=a-b else: d=b-a print("Sum = ",s) print("Product = ",p) print("Difference = ",d)
Output:
Enter 1st no 10
Enter 2nd no 20
Sum = 30
Product = 200
Difference = 10
>>>
Question:3
Write a python script to take input for 3 numbers, check and print the largest number?
a=int(input("Enter 1st no ")) b=int(input("Enter 2nd no ")) c=int(input("Enter 3rd no ")) if(a>b and a>c): m=a else: if(b>c): m=b else: m=c print("Max no = ",m)
Output:
Enter 1st no 25
Enter 2nd no 63
Enter 3rd no 24
Max no = 63
>>>
Method:2
a=int(input("Enter 1st no ")) b=int(input("Enter 2nd no ")) c=int(input("Enter 3rd no ")) if(a>b and a>c): m=a elif(b>c): m=b else: m=c print("Max no = ",m)
Output:
Enter 1st no 25
Enter 2nd no 98
Enter 3rd no 63
Max no = 98
>>>
Question:4
Write a python script to take input for 2 numbers and an operator (+ , – , * , / ). Based on the operator calculate and print the result?
a=int(input("Enter 1st no ")) b=int(input("Enter 2nd no ")) op=input("Enter the operator (+,-,,/) ") if(op=="+"): c=a+b print("Sum = ",c) elif(op==""): c=a*b print("Product = ",c) elif(op=="-"): if(a>b): c=a-b else: c=b-a print("Difference = ",c) elif(op=="/"): c=a/b print("Division = ",c) else: print("Invalid operator")
Output:
Enter 1st no 10
Enter 2nd no 20
Enter the operator (+,-,*,/) +
Sum = 30
>>>
Output:
Enter 1st no 10
Enter 2nd no 36
Enter the operator (+,-,*,/) –
Difference = 26
>>>
Question:5
Write a python script to take input for name and age of a person check and print whether the person can vote or not?
name=input("Enter name ") age=int(input("Enter age ")) if(age>=18): print("you can vote") else: print("you cannot vote")
CBSE Class 12 @ Python
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions C Programs C++ Programs |