Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
3 views
Python
Uploaded by
Shimrah akram Khan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save python For Later
Download
Save
Save python For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
3 views
Python
Uploaded by
Shimrah akram Khan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save python For Later
Carousel Previous
Carousel Next
Save
Save python For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 2
Search
Fullscreen
c) String slicing.
ARMSTRONG FIBONACII def string_slicing(text):
print("Original string:", text)
def is_armstrong_number(num): def fibonacci(n):
fib_series = [] print("First three characters:", text[:3])
num_str = str(num) if n <= 0: print("Characters from index 3 to 7:", text[3:8])
num_digits = len(num_str) return fib_series print("Last five characters:", text[-5:])
sum_of_cubes = 0 elif n == 1: print("Every second character:", text[::2])
fib_series.append(0) print("Reversed string:", text[::-1])
for digit in num_str: else:
def main():
sum_of_cubes += int(digit) ** num_digits fib_series = [0, 1] text = "Python Programming"
for i in range(2, n):
return sum_of_cubes == num string_slicing(text)
fib_series.append(fib_series[-1] + fib_series[-2])
def main(): return fib_series if __name__ == "__main__":
main()
num = int(input("Enter a number: ")) def main():
n = int(input("Enter the value of n to display the first n Fibonacci numbers: "))
if is_armstrong_number(num): if n <= 0:
CHECK STRING OPERATIONS
print(num, "is an Armstrong number.") print("Please enter a positive integer.")
a) len(), split(), join(), upper(), lower(), swapcase(), title(),
else:
else:
fib_series = fibonacci(n)
print(num, "is not an Armstrong number.") print("First", n, "Fibonacci numbers:") def string_operations(text):
print("Original string:", text)
if __name__ == "__main__": print(fib_series)
print("Length of the string:", len(text))
if __name__ == "__main__":
main() main()
print("Splitting the string:", text.split())
print("Joining the string with '_':", '_'.join(text.split()))
print("Uppercase:", text.upper())
FACTORIAL OF A NUMBER
print("Lowercase:", text.lower()) print("Swapping case:", text.swapcase())
def factorial_recursive(n): print("Title case:", text.title())
if n == 0: def main():
return 1 text = input("Enter a string: ")
string_operations(text)
else: if __name__ == "__main__":
return n * factorial_recursive(n - 1) main()
def main(): b) Find(), index(), count(), replace(), sorted(), strip()
def string_operations(text):
num = int(input("Enter a number: ")) print("Original string:", text)
if num < 0: print("Finding 'world':", text.find('world'))
print("Factorial is not defined for negative numbers.") print("Index of 'world':", text.index('world'))
print("Count of 'o':", text.count('o'))
else:
print("Replacing 'world' with 'Python':", text.replace('world', 'Python'))
result = factorial_recursive(num) print("Sorted characters:", sorted(text))
print("Factorial of", num, "is:", result) print("Stripped string:", text.strip())
def main():
text = " hello world! "
if __name__ == "__main__": main() string_operations(text)
main() if __name__ == "__main__":
main()
Check List and Tuple Operations. Check Dictionary and Set Operations Set Operations
a. len(), append(), extend(), insert(), remove(). i. Add Element ix.union()
my_dict = {'a': 1, 'b': 2} set1 = {1, 2, 3}
my_list = [1, 2, 3, 4, 5]
my_dict['c'] = 3 set2 = {3, 4, 5}
print(len(my_list))
print(my_dict) union_set = set1.union(set2)
my_list = [1, 2, 3]
ii.Modify Element print(union_set)
my_list.append(4) my_dict = {'a': 1, 'b': 2} x. intersection()
print(my_list) my_dict['a'] = 10 set1 = {1, 2, 3}
Print(my_dict) set2 = {3, 4, 5}
my_list = [1, 2, 3] iii. Delete Element intersection_set = set1.intersection(set2)
my_list.extend([4, 5]) my_dict = {'a': 1, 'b': 2, 'c': 3} print(intersection_set)
print(my_list) del my_dict['b'] xi. difference()
print(my_dict) set1 = {1, 2, 3}
my_list = [1, 2, 4]
iv. clear() set2 = {3, 4, 5}
my_list.insert(2, 3)
print(my_list)
my_dict = {'a': 1, 'b': 2, 'c': 3} difference_set = set1.difference(set2)
my_dict.clear() print(difference_set)
my_list = [1, 2, 3, 4, 3] print(my_dict) xii. symmetric_difference()
my_list.remove(3) v. copy() set1 = {1, 2, 3}
print(my_list) my_dict = {'a': 1, 'b': 2} new_dict = set2 = {3, 4, 5}
my_dict.copy() symmetric_difference_set =set1.symmetric_difference(set2)
b. reverse(), clear(), sort(), sorted(), count() print(new_dict) print(symmetric_difference_set)
my_list = [1, 2, 3, 4]
vi. values()
my_list.reverse() b) Modify Index of the Data and Sort the Index
my_dict = {'a': 1, 'b': 2, 'c': 3}
print(my_list)
values = my_dict.values() Modify
print(values) df.set_index('Name', inplace=True)
my_list = [1, 2, 3, 4]
my_list.clear() vii. keys() print("\nDataFrame with modified index:")
print(my_list) my_dict = {'a': 1, 'b': 2, 'c': 3} print(df)
keys = my_dict.keys()
my_list = [4, 2, 1, 3] print(keys) Sort
my_list.sort() viii.items() df.sort_index(inplace=True)
print(my_list) print("\nDataFrame after sorting index:")
my_dict = {'a': 1, 'b': 2, 'c': 3}
my_list = [4, 2, 1, 3] print(df)
items = my_dict.items()
new_list = sorted(my_list)
print(new_list)
print(items)
print(my_list)
my_list = [1, 2, 3, 2, 2, 4]
print(my_list.count(2))
You might also like
Python Hands On
PDF
100% (1)
Python Hands On
11 pages
Python 2
PDF
No ratings yet
Python 2
2 pages
Python Programs
PDF
No ratings yet
Python Programs
26 pages
Record file
PDF
No ratings yet
Record file
35 pages
Python Lab - Programs
PDF
No ratings yet
Python Lab - Programs
27 pages
Ai Lab Internal - 1
PDF
No ratings yet
Ai Lab Internal - 1
3 pages
DOC-20250129-WA0006. (2)
PDF
No ratings yet
DOC-20250129-WA0006. (2)
13 pages
DS Lab Programs (1)
PDF
No ratings yet
DS Lab Programs (1)
47 pages
python_record_code
PDF
No ratings yet
python_record_code
33 pages
Pyhton Data Structure CheatSheet
PDF
No ratings yet
Pyhton Data Structure CheatSheet
5 pages
DSD RECORD 2
PDF
No ratings yet
DSD RECORD 2
51 pages
Pytxt
PDF
No ratings yet
Pytxt
4 pages
CS HHW
PDF
No ratings yet
CS HHW
7 pages
ds
PDF
No ratings yet
ds
6 pages
Python Programming Lab
PDF
No ratings yet
Python Programming Lab
10 pages
Lab-manual-Advanced Python Programming 4321602
PDF
No ratings yet
Lab-manual-Advanced Python Programming 4321602
24 pages
DATA STRUCTURE FINAL LAB MANUAL
PDF
No ratings yet
DATA STRUCTURE FINAL LAB MANUAL
57 pages
lab2_Python
PDF
No ratings yet
lab2_Python
5 pages
Lab2 Python
PDF
No ratings yet
Lab2 Python
5 pages
Python Answers
PDF
No ratings yet
Python Answers
6 pages
ds1
PDF
No ratings yet
ds1
6 pages
PDF
PDF
No ratings yet
PDF
13 pages
Computer Program PDF
PDF
No ratings yet
Computer Program PDF
33 pages
Kashu
PDF
No ratings yet
Kashu
25 pages
PYTHON_LAB_MANUAL[1]
PDF
No ratings yet
PYTHON_LAB_MANUAL[1]
12 pages
Python Programs
PDF
No ratings yet
Python Programs
6 pages
python assignment
PDF
No ratings yet
python assignment
6 pages
Python Solutions
PDF
No ratings yet
Python Solutions
11 pages
Practical File
PDF
No ratings yet
Practical File
42 pages
PYTHON PROGRAM LIST
PDF
No ratings yet
PYTHON PROGRAM LIST
13 pages
03.python.04.stringslistsdictionaries
PDF
No ratings yet
03.python.04.stringslistsdictionaries
47 pages
Summary Python
PDF
No ratings yet
Summary Python
4 pages
python_lab_A_B
PDF
No ratings yet
python_lab_A_B
13 pages
USER DEFINED MODULE ARYAN
PDF
No ratings yet
USER DEFINED MODULE ARYAN
29 pages
DS 8-12
PDF
No ratings yet
DS 8-12
5 pages
cbc86808-82ba-48d0-b8d1-34b4e3ce7c98
PDF
No ratings yet
cbc86808-82ba-48d0-b8d1-34b4e3ce7c98
17 pages
12 Programs Reformatted
PDF
No ratings yet
12 Programs Reformatted
22 pages
Python Manual For M.SC CS
PDF
No ratings yet
Python Manual For M.SC CS
45 pages
Untitled Document
PDF
No ratings yet
Untitled Document
8 pages
Python Week 4 All GrPA's Solutions
PDF
100% (1)
Python Week 4 All GrPA's Solutions
8 pages
Python Unit 3
PDF
No ratings yet
Python Unit 3
4 pages
1a.install Python and Set Up The Development Environment.: Code: Print ("Hello World") Output
PDF
No ratings yet
1a.install Python and Set Up The Development Environment.: Code: Print ("Hello World") Output
14 pages
python lab
PDF
No ratings yet
python lab
5 pages
Week 4 All Grpa
PDF
No ratings yet
Week 4 All Grpa
6 pages
CSCI Final Cheat Sheet
PDF
No ratings yet
CSCI Final Cheat Sheet
14 pages
Class 12 Python Programs
PDF
No ratings yet
Class 12 Python Programs
6 pages
# Addition of List Elements.
PDF
No ratings yet
# Addition of List Elements.
16 pages
19BBTCS069 KrishnaKantPandey DAP Lab Record
PDF
No ratings yet
19BBTCS069 KrishnaKantPandey DAP Lab Record
100 pages
python_lab-1
PDF
No ratings yet
python_lab-1
8 pages
Cheat Sheet
PDF
No ratings yet
Cheat Sheet
2 pages
AI & ML Practical 1
PDF
No ratings yet
AI & ML Practical 1
10 pages
Ch7 Lists
PDF
No ratings yet
Ch7 Lists
3 pages
SolutionOfPythonQS 23-24
PDF
No ratings yet
SolutionOfPythonQS 23-24
21 pages
AI Part A Programs
PDF
No ratings yet
AI Part A Programs
10 pages
ANSWERS of Practical
PDF
No ratings yet
ANSWERS of Practical
7 pages
Python cheatsheet
PDF
No ratings yet
Python cheatsheet
2 pages
GE3171 - Python Lab PDF
PDF
No ratings yet
GE3171 - Python Lab PDF
55 pages
DSA Program Print-Out
PDF
No ratings yet
DSA Program Print-Out
58 pages
Profound Python Data Science
From Everand
Profound Python Data Science
Onder Teker
No ratings yet
The Essential R Reference
From Everand
The Essential R Reference
Mark Gardener
No ratings yet
Logarithm
PDF
No ratings yet
Logarithm
2 pages
6 Maths wk2 July Pooja
PDF
No ratings yet
6 Maths wk2 July Pooja
2 pages
Various Arithmetic Functions and Their Applications
PDF
No ratings yet
Various Arithmetic Functions and Their Applications
402 pages
Soal Model
PDF
No ratings yet
Soal Model
4 pages
Guevarra Discreet Math PT
PDF
No ratings yet
Guevarra Discreet Math PT
3 pages
Factors and Prime and Composite Numbers
PDF
100% (1)
Factors and Prime and Composite Numbers
27 pages
Prime Factors HCF and LCM wZmfp5nFrTWkh3 B
PDF
No ratings yet
Prime Factors HCF and LCM wZmfp5nFrTWkh3 B
9 pages
Mersenne Numbers and Fermat Numbers
PDF
No ratings yet
Mersenne Numbers and Fermat Numbers
327 pages
Logarithms DPP
PDF
No ratings yet
Logarithms DPP
2 pages
My Test
PDF
No ratings yet
My Test
13 pages
1699104193
PDF
No ratings yet
1699104193
3 pages
Factoring Perfect Square Trinomials: Designed by Skip Tyler, Varina High School
PDF
100% (1)
Factoring Perfect Square Trinomials: Designed by Skip Tyler, Varina High School
16 pages
Factors, Primes & Composite Numbers: by Monica Yuskaitis
PDF
100% (1)
Factors, Primes & Composite Numbers: by Monica Yuskaitis
30 pages
Number - Theory 17 4 PDF
PDF
No ratings yet
Number - Theory 17 4 PDF
2 pages
2024 PiMC Fermat Division Solutions
PDF
No ratings yet
2024 PiMC Fermat Division Solutions
13 pages
13 Logarithms
PDF
No ratings yet
13 Logarithms
2 pages
Tutorial For Basic Mathematics
PDF
No ratings yet
Tutorial For Basic Mathematics
126 pages
Mental Math Grade 6
PDF
No ratings yet
Mental Math Grade 6
2 pages
Prime Numbers Presentation
PDF
No ratings yet
Prime Numbers Presentation
19 pages
Number Theory Notes Anwar Khan
PDF
No ratings yet
Number Theory Notes Anwar Khan
219 pages
Richard Crandall, Carl B. Pomerance - Prime Numbers - A Computational Perspective (2005, Springer)
PDF
No ratings yet
Richard Crandall, Carl B. Pomerance - Prime Numbers - A Computational Perspective (2005, Springer)
81 pages
Prime Final
PDF
No ratings yet
Prime Final
7 pages
HCF & LCM
PDF
No ratings yet
HCF & LCM
27 pages
Number Sense - Workbook 8, Part 1: Worksheet NS8-58
PDF
No ratings yet
Number Sense - Workbook 8, Part 1: Worksheet NS8-58
2 pages
Prime Numbers
PDF
No ratings yet
Prime Numbers
18 pages
2014 10 30 Polygonal Numbers
PDF
No ratings yet
2014 10 30 Polygonal Numbers
1 page
Fermat Pseudoprime
PDF
No ratings yet
Fermat Pseudoprime
14 pages
Logarithms - 9th, 10
PDF
No ratings yet
Logarithms - 9th, 10
3 pages
Arturo Garcia
PDF
No ratings yet
Arturo Garcia
21 pages
028 Factor ClassRoom Sheet MATHEMATICS NUMBER SYSTEM संख्य
PDF
No ratings yet
028 Factor ClassRoom Sheet MATHEMATICS NUMBER SYSTEM संख्य
3 pages