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)
2 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)
2 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
2019 Maths Real Analysis PDF
PDF
No ratings yet
2019 Maths Real Analysis PDF
12 pages
Gmail - Free Chegg Answer From TechLaCarte
PDF
50% (2)
Gmail - Free Chegg Answer From TechLaCarte
48 pages
Harmonic Sequences Answers
PDF
100% (3)
Harmonic Sequences Answers
3 pages
Python 2
PDF
No ratings yet
Python 2
2 pages
python pdf
PDF
No ratings yet
python pdf
1 page
Programming Essentials in Python
PDF
No ratings yet
Programming Essentials in Python
23 pages
Exam Lab Manual
PDF
No ratings yet
Exam Lab Manual
11 pages
Programs Related To Python
PDF
No ratings yet
Programs Related To Python
22 pages
Exp1 and 2 Python
PDF
No ratings yet
Exp1 and 2 Python
10 pages
Python Record
PDF
No ratings yet
Python Record
30 pages
Plc Additional Programs
PDF
No ratings yet
Plc Additional Programs
5 pages
python practical exam sol
PDF
No ratings yet
python practical exam sol
6 pages
Python Imp Pro: Write A Python Program To Print Fibonacci Series Up To N Terms
PDF
No ratings yet
Python Imp Pro: Write A Python Program To Print Fibonacci Series Up To N Terms
14 pages
Programs
PDF
No ratings yet
Programs
9 pages
Python Lab Manual Created
PDF
No ratings yet
Python Lab Manual Created
13 pages
So Lab Manual
PDF
No ratings yet
So Lab Manual
10 pages
Keeraiit 2
PDF
No ratings yet
Keeraiit 2
19 pages
Ujjwal
PDF
No ratings yet
Ujjwal
17 pages
Pyhton Practicals PDF
PDF
No ratings yet
Pyhton Practicals PDF
17 pages
Python Programming Lab Manual (Solved)
PDF
No ratings yet
Python Programming Lab Manual (Solved)
33 pages
hill cipher
PDF
No ratings yet
hill cipher
4 pages
DVP Manual V2
PDF
No ratings yet
DVP Manual V2
26 pages
Class-XII Computer Science
PDF
No ratings yet
Class-XII Computer Science
44 pages
ajay py
PDF
No ratings yet
ajay py
1 page
practicals_pythoncode24_25
PDF
No ratings yet
practicals_pythoncode24_25
7 pages
Practical File- 20 codes
PDF
No ratings yet
Practical File- 20 codes
16 pages
Python Final Assignment Imp
PDF
No ratings yet
Python Final Assignment Imp
12 pages
Python manual
PDF
No ratings yet
Python manual
10 pages
Practical Assignment Xi SC (CS) - 2022-23
PDF
No ratings yet
Practical Assignment Xi SC (CS) - 2022-23
8 pages
OSDBMS
PDF
No ratings yet
OSDBMS
59 pages
Phython
PDF
No ratings yet
Phython
19 pages
All Document Reader 1724857804883
PDF
No ratings yet
All Document Reader 1724857804883
6 pages
Python Cheat Sheet: by Via
PDF
No ratings yet
Python Cheat Sheet: by Via
3 pages
Python3 Cheat Sheet - Language - V3.0
PDF
No ratings yet
Python3 Cheat Sheet - Language - V3.0
2 pages
Python Lab Programs
PDF
100% (1)
Python Lab Programs
8 pages
Python PF
PDF
No ratings yet
Python PF
39 pages
Pythonn
PDF
No ratings yet
Pythonn
12 pages
Python Imp Program Msbte Campus Academy
PDF
No ratings yet
Python Imp Program Msbte Campus Academy
14 pages
31 48codetantra Programs
PDF
No ratings yet
31 48codetantra Programs
13 pages
Alm Co-1 PDF
PDF
No ratings yet
Alm Co-1 PDF
9 pages
Python Class PRG
PDF
No ratings yet
Python Class PRG
54 pages
Class 12 Practicals 20 Prgs 5
PDF
No ratings yet
Class 12 Practicals 20 Prgs 5
59 pages
Mis 211
PDF
No ratings yet
Mis 211
17 pages
Cheat Sheet - Gnuplot2
PDF
No ratings yet
Cheat Sheet - Gnuplot2
1 page
Write A Python Code To Print The Sum of Natural Numbers Using Recursive Functions
PDF
No ratings yet
Write A Python Code To Print The Sum of Natural Numbers Using Recursive Functions
21 pages
Python Strings
PDF
No ratings yet
Python Strings
10 pages
Python Lab Manual
PDF
No ratings yet
Python Lab Manual
18 pages
Assignment 2
PDF
No ratings yet
Assignment 2
9 pages
python output
PDF
No ratings yet
python output
11 pages
Chapter 4
PDF
No ratings yet
Chapter 4
55 pages
Complete Unit 3
PDF
No ratings yet
Complete Unit 3
104 pages
RishabhJhapython Labs pt2
PDF
No ratings yet
RishabhJhapython Labs pt2
40 pages
עבודה מדמח סוף
PDF
No ratings yet
עבודה מדמח סוף
4 pages
Python Codes
PDF
No ratings yet
Python Codes
9 pages
Kashu
PDF
No ratings yet
Kashu
25 pages
Python Practical programs
PDF
No ratings yet
Python Practical programs
18 pages
Pyhton Functions Cs
PDF
No ratings yet
Pyhton Functions Cs
23 pages
PES1UG22AM181_CD_LAB2 (1)
PDF
No ratings yet
PES1UG22AM181_CD_LAB2 (1)
5 pages
Alm Co-2 PDF
PDF
No ratings yet
Alm Co-2 PDF
11 pages
Optional Assignment 1
PDF
No ratings yet
Optional Assignment 1
11 pages
Python Exam Cheat Sheet
PDF
No ratings yet
Python Exam Cheat Sheet
5 pages
List of Cs Practicals Class 12 2022-23
PDF
No ratings yet
List of Cs Practicals Class 12 2022-23
17 pages
Profound Python Data Science
From Everand
Profound Python Data Science
Onder Teker
No ratings yet
Sequence Series Tough JEE Advanced
PDF
No ratings yet
Sequence Series Tough JEE Advanced
4 pages
Topic_10.2___Working_with_Geometric_Series___SOLUTIONS.pdf
PDF
No ratings yet
Topic_10.2___Working_with_Geometric_Series___SOLUTIONS.pdf
5 pages
Unit Vi
PDF
No ratings yet
Unit Vi
21 pages
4 61 60603 MQGM Prel SM 3E 04
PDF
No ratings yet
4 61 60603 MQGM Prel SM 3E 04
20 pages
Notes 04 - Sequences 1
PDF
No ratings yet
Notes 04 - Sequences 1
35 pages
Mathematics in The Modern World: Number Sequence and Series
PDF
No ratings yet
Mathematics in The Modern World: Number Sequence and Series
12 pages
FN Y An-: Lim Sup FN NFN Lim Inf FN
PDF
No ratings yet
FN Y An-: Lim Sup FN NFN Lim Inf FN
2 pages
9.5 - Testing Convergence at Endpoints
PDF
No ratings yet
9.5 - Testing Convergence at Endpoints
13 pages
Spring15 M2108 Test2 Soln
PDF
No ratings yet
Spring15 M2108 Test2 Soln
3 pages
Hörsaal-Übung 5 Mathematik 1
PDF
No ratings yet
Hörsaal-Übung 5 Mathematik 1
76 pages
Smarandache Sequence of Happy Cube Numbers
PDF
No ratings yet
Smarandache Sequence of Happy Cube Numbers
5 pages
Prime Composite2
PDF
No ratings yet
Prime Composite2
2 pages
GR 10 Arithmetic Progressions Practice Worksheet - 1 Answer Key
PDF
No ratings yet
GR 10 Arithmetic Progressions Practice Worksheet - 1 Answer Key
13 pages
Infinte Series Notes
PDF
No ratings yet
Infinte Series Notes
5 pages
Sequence & Series 01 Unsolved Notes Only PDF.pdf
PDF
No ratings yet
Sequence & Series 01 Unsolved Notes Only PDF.pdf
29 pages
Study Sheet 11.8-11.9
PDF
No ratings yet
Study Sheet 11.8-11.9
14 pages
MA1010 Notes 1
PDF
No ratings yet
MA1010 Notes 1
38 pages
Grade 10 Math Quiz 2
PDF
No ratings yet
Grade 10 Math Quiz 2
1 page
Chapter Test-Sequence & Series
PDF
No ratings yet
Chapter Test-Sequence & Series
2 pages
Ramanujan Summation of Divergent Series-Springer (2017) - by Candelpergher, Bernard
PDF
100% (4)
Ramanujan Summation of Divergent Series-Springer (2017) - by Candelpergher, Bernard
211 pages
T. Y. B. Sc. (Sem. - V) Examination March - 2023 Mathematics: MTH - 503 Real Analysis - I (New Course)
PDF
No ratings yet
T. Y. B. Sc. (Sem. - V) Examination March - 2023 Mathematics: MTH - 503 Real Analysis - I (New Course)
2 pages
Chapter 1 Review Revised
PDF
No ratings yet
Chapter 1 Review Revised
3 pages
Hmw7 (MA 504)
PDF
No ratings yet
Hmw7 (MA 504)
6 pages
Math10-Las.1st - Week 1-5
PDF
No ratings yet
Math10-Las.1st - Week 1-5
7 pages
Ap &GP
PDF
No ratings yet
Ap &GP
5 pages
Mal 512 PDF
PDF
No ratings yet
Mal 512 PDF
132 pages
Regular Prime: Unsolved Problem in Mathematics
PDF
No ratings yet
Regular Prime: Unsolved Problem in Mathematics
12 pages