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

Python Code Snippets Made by Tanish Raina

The document contains various Python code snippets demonstrating arithmetic operations, decision control statements, and basic programming concepts. It includes examples for checking voting eligibility, determining positive/negative numbers, finding the largest number, calculating factorials, displaying multiplication tables, and more. Each code snippet is accompanied by sample output to illustrate the results of the operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

Python Code Snippets Made by Tanish Raina

The document contains various Python code snippets demonstrating arithmetic operations, decision control statements, and basic programming concepts. It includes examples for checking voting eligibility, determining positive/negative numbers, finding the largest number, calculating factorials, displaying multiplication tables, and more. Each code snippet is accompanied by sample output to illustrate the results of the operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Python Code Snippets

UNIT 2 ADVANCE DATA TYPES AND DECISION CONTROL STATEMENTS


Q1] Write a Python program code for arithmetic operations.
(A) Addition:

Output:
The sum is: 12

(B) Subtraction:

Output:
The subtraction is: 4

(C) Multiplication:

Output:
The multiplication is: 60
(D)Division:

Output:
The division is: 5.0

Q2] Check if user is eligible for voting

Output:
What is your age? 18
You are eligible to vote.

Q3] Check if a Number is Positive, Negative or 0

Output:
Enter a number: 10
Positive number
Q4] Check if a Number is Odd or Even

Output:
Enter a number: 7
The number is odd.

Q5] Python Program to Check Leap Year

Output:
Enter year: 2025
The year isn’t a leap year!

Q6] Python Program to Find the Largest among two numbers

Output:
Enter the first number: 5
Enter the second number: 9
The second number is greater.

Q7] Python Program to Find the Largest among Three numbers

Output:
Enter the first number:10
Enter the second number:15
Enter the third number:12
The largest number is 15

Q8] Find the Factorial of a Number

Output:
1 24
2 120
6
Q9] Python program to display multiplication table

Output:
Enter a number for table:5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Q10] Python program to display addition of first 10 numbers

Output:
55
Q11] Python Program to Print the Fibonacci sequence

Output:
Enter a number:8
0
1
1
2
3
5
8
13
Q12] Python Program to Check Prime Number

Output:
Enter a number: 9
9 is not prime.
Q13] Python Program to Swap Two Variables

Output:
Enter value1: 5
Enter value2: 6
The value of a after swapping: 6
The value of b after swapping: 5

Q14] Python Program to Check Armstrong Number

Output:
Enter a number: 370
370 is an Armstrong number

Made By: TANISH RAINA(1161)

You might also like