0% found this document useful (0 votes)
7 views14 pages

Python Practical Programs With Output

The document contains a series of Python code snippets demonstrating various programming concepts such as pattern printing, voting eligibility, student grading, and list operations. Each code snippet is followed by its expected output, illustrating how the code functions. The examples cover basic programming constructs including loops, conditionals, and list manipulations.

Uploaded by

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

Python Practical Programs With Output

The document contains a series of Python code snippets demonstrating various programming concepts such as pattern printing, voting eligibility, student grading, and list operations. Each code snippet is followed by its expected output, illustrating how the code functions. The examples cover basic programming constructs including loops, conditionals, and list manipulations.

Uploaded by

tinadhupar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

11(a).

Pattern Printing

Code:
print("*") print("* *") print("* * *") print("* * * *") print("* * * * *")

Output:
* * * * * * * * * * * * * * *
11(b). Reverse Pattern

Code:
print("* * * * *") print("* * * *") print("* * *") print("* *") print("*")

Output:
* * * * * * * * * * * * * * *
12. Voting Eligibility

Code:
age = int(input("Enter age: ")) if age >= 18: print("Eligible to vote") else:
print("Not eligible to vote")

Output:
Enter age: 20 Eligible to vote
13. Student Grade

Code:
marks = int(input("Enter marks: ")) if marks >= 90: print("Grade A") elif marks >=
75: print("Grade B") elif marks >= 50: print("Grade C") else: print("Fail")

Output:
Enter marks: 82 Grade B
14. Positive / Negative / Zero

Code:
num = int(input("Enter a number: ")) if num > 0: print("Positive number") elif num <
0: print("Negative number") else: print("Zero")

Output:
Enter a number: -4 Negative number
15. First 10 Natural Numbers

Code:
for i in range(1, 11): print(i)

Output:
1 2 3 4 5 6 7 8 9 10
16. First 10 Even Numbers

Code:
for i in range(2, 21, 2): print(i)

Output:
2 4 6 8 10 12 14 16 18 20
17. Odd Numbers from 1 to n

Code:
n = int(input("Enter n: ")) for i in range(1, n+1, 2): print(i)

Output:
Enter n: 10 1 3 5 7 9
18. Sum of First 10 Natural Numbers

Code:
sum = 0 for i in range(1, 11): sum += i print("Sum =", sum)

Output:
Sum = 55
19. Sum of List Elements

Code:
numbers = [10, 20, 30, 40] print("Sum =", sum(numbers))

Output:
Sum = 100
20. List Operations

Code:
students = ["Arjun","Sonakshi","Vikram","Sandhya","Sonal","Isha","Kartik"]
print(students) [Link]("Vikram") [Link]("Jay") [Link](1)
print(students)

Output:
['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik'] ['Arjun',
'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']
21. List Indexing

Code:
num = [23,12,5,9,65,44] print(len(num)) print(num[1:4]) print(num[-4:-1])

Output:
6 [12, 5, 9] [5, 9, 65]
22. Add 1 to First 10 Even Numbers

Code:
even = [] for i in range(2, 21, 2): [Link](i+1) print(even)

Output:
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
23. Extend and Sort List

Code:
list_1 = [10,20,30,40] list_1.extend([14,15,12]) list_1.sort() print(list_1)

Output:
[10, 12, 14, 15, 20, 30, 40]

You might also like