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

Gaurisha Python Work

The document is a practical file for Grade 11 Computer Science by Gaurisha Rastogi, containing various programming exercises. It includes tasks such as displaying messages, finding largest/smallest numbers, generating patterns, calculating series sums, and checking for prime numbers. Additionally, it covers string manipulations, list operations, and dictionary handling in Python.

Uploaded by

kevari1588
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)
3 views9 pages

Gaurisha Python Work

The document is a practical file for Grade 11 Computer Science by Gaurisha Rastogi, containing various programming exercises. It includes tasks such as displaying messages, finding largest/smallest numbers, generating patterns, calculating series sums, and checking for prime numbers. Additionally, it covers string manipulations, list operations, and dictionary handling in Python.

Uploaded by

kevari1588
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

Computer Practical File

Name - Gaurisha Rastogi


Grade - 11 science
Subject - Computer
Submitted to - Mr Sarfaraz
1. Input a welcome message and display it
msg = input("Enter a welcome message: ")
print("Your message is:", msg)

2. Input two numbers and display the larger/smaller number


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Larger number:", max(a, b))
print("Smaller number:", min(a, b))

3. Input three numbers and display the largest/smallest


number
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
print("Largest number:", max(a, b, c))
print("Smallest number:", min(a, b, c))
4. Generate patterns using nested loops
Pattern-1
for i in range(1, 6):
print("*" * i)
Pattern-2
for i in range(5, 0, -1):
for j in range(1, i+1):
print(j, end="")
print()
Pattern-3
for i in range(1, 6):
for j in range(65, 65+i):
print(chr(j), end="")
print()
5. Program for series sum (1 + x + x² + … + xⁿ)
x = int(input("Enter value of x: "))
n = int(input("Enter value of n: "))

s=0
for i in range(n+1):
s += x**i
print("Sum of series:", s)

6. Perfect number, Armstrong number, Palindrome


n = int(input("Enter a number: "))

# Perfect number
s = sum([i for i in range(1, n) if n % i == 0])
print("Perfect number?" , s == n)

# Armstrong number
num = n
order = len(str(n))
s = sum(int(digit)**order for digit in str(n))
print("Armstrong number?", s == num)

# Palindrome
print("Palindrome?", str(n) == str(n)[::-1])

7. Prime or Composite
n = int(input("Enter a number: "))
if n < 2:
print("Neither prime nor composite")
else:
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
print("Composite number")
break
else:
print("Prime number")

8. Fibonacci Series
n = int(input("Enter number of terms: "))
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b

9. GCD and LCM


import math

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

gcd = [Link](a, b)
lcm = abs(a*b) // gcd

print("GCD:", gcd)
print("LCM:", lcm)

10. Count vowels, consonants, upper, lower


s = input("Enter a string: ")

vowels = "aeiouAEIOU"
v_count = sum(1 for ch in s if ch in vowels)
c_count = sum(1 for ch in s if [Link]() and ch not in vowels)
u_count = sum(1 for ch in s if [Link]())
l_count = sum(1 for ch in s if [Link]())

print("Vowels:", v_count)
print("Consonants:", c_count)
print("Uppercase:", u_count)
print("Lowercase:", l_count)

11. Palindrome check + Convert case


s = input("Enter a string: ")

print("Palindrome?", s == s[::-1])
print("Case swapped:", [Link]())

12. Largest/Smallest number in list/tuple


nums = [int(x) for x in input("Enter numbers separated by space: ").split()]
print("Largest:", max(nums))
print("Smallest:", min(nums))

13. Swap even and odd elements


nums = [int(x) for x in input("Enter numbers separated by space: ").split()]

for i in range(0, len(nums)-1, 2):

nums[i], nums[i+1] = nums[i+1], nums[i]

print("After swapping:", nums)

14. Search element in list/tuple


nums = [int(x) for x in input("Enter numbers separated by space: ").split()]
search = int(input("Enter element to search: "))

if search in nums:
print("Element found at index:", [Link](search))
else:
print("Element not found")
15. Dictionary with roll, name, marks & filter marks > 75
n = int(input("Enter number of students: "))
students = {}

for _ in range(n):
roll = input("Enter roll number: ")
name = input("Enter name: ")
marks = int(input("Enter marks: "))
students[roll] = {"name": name, "marks": marks}

print("\nStudents with marks > 75:")


for roll, info in [Link]():
if info["marks"] > 75:
print(info["name"])

You might also like