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
Layout For Graphic Designers An Introduction 3rd Edition Gavin Ambrose & Paul Harris 2024 Scribd Download
PDF
100% (11)
Layout For Graphic Designers An Introduction 3rd Edition Gavin Ambrose & Paul Harris 2024 Scribd Download
60 pages
The Great Pyramid
PDF
100% (3)
The Great Pyramid
12 pages
The Sacred Geometry Light Source Experience Manual
PDF
100% (3)
The Sacred Geometry Light Source Experience Manual
16 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
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
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
Write A Program To Capitalize First and Last Letter of Given String
PDF
No ratings yet
Write A Program To Capitalize First and Last Letter of Given String
45 pages
List of Cs Practicals Class 12 2022-23
PDF
No ratings yet
List of Cs Practicals Class 12 2022-23
17 pages
DVPY Lab
PDF
No ratings yet
DVPY Lab
20 pages
Profound Python Data Science
From Everand
Profound Python Data Science
Onder Teker
No ratings yet
An Analysis of Geometrical Factors, Golden Ratio and Nataraja
PDF
No ratings yet
An Analysis of Geometrical Factors, Golden Ratio and Nataraja
5 pages
Mathematics in The Modern World
PDF
No ratings yet
Mathematics in The Modern World
44 pages
Number Systems: History and Evolution of Irrational Numbers
PDF
No ratings yet
Number Systems: History and Evolution of Irrational Numbers
62 pages
Mathematics in The Modern World: Sibonga Community College
PDF
No ratings yet
Mathematics in The Modern World: Sibonga Community College
10 pages
Inverting The Fibonacci Sequence: Sequence For Centuries. It Starts As A Simple
PDF
No ratings yet
Inverting The Fibonacci Sequence: Sequence For Centuries. It Starts As A Simple
6 pages
The Golden Ratio
PDF
No ratings yet
The Golden Ratio
2 pages
Math Lesson-2 Answers
PDF
No ratings yet
Math Lesson-2 Answers
8 pages
4.6 - Primary Unit of Measure Planck Length by The Exponent of The Golden Ratio or by Duplication
PDF
No ratings yet
4.6 - Primary Unit of Measure Planck Length by The Exponent of The Golden Ratio or by Duplication
3 pages
Constructions For The Golden Ratio
PDF
No ratings yet
Constructions For The Golden Ratio
6 pages
GEED-10053 MMWFinalVer1 (STEM)
PDF
100% (2)
GEED-10053 MMWFinalVer1 (STEM)
58 pages
Golden-Ratio Principle in Car Engine Air Cooling
PDF
No ratings yet
Golden-Ratio Principle in Car Engine Air Cooling
4 pages
Symmetry As A Compositional Determinant VII Bartok & Webern
PDF
100% (1)
Symmetry As A Compositional Determinant VII Bartok & Webern
18 pages
Mathematics in The Modern World L1
PDF
100% (1)
Mathematics in The Modern World L1
39 pages
Arch 70 - Lesson 1 - Design in Architecture
PDF
No ratings yet
Arch 70 - Lesson 1 - Design in Architecture
26 pages
GEC104 Module Midterm Final 2022
PDF
No ratings yet
GEC104 Module Midterm Final 2022
46 pages
Fibonacci Numbers and Golden Ratio
PDF
No ratings yet
Fibonacci Numbers and Golden Ratio
47 pages
Dimensions Great Pyramid
PDF
100% (1)
Dimensions Great Pyramid
5 pages
Nikos Salingaros-Architecture, Patterns, and Mathematics PDF
PDF
No ratings yet
Nikos Salingaros-Architecture, Patterns, and Mathematics PDF
11 pages
Engineering of Alphabets by Bahaa Dergham Montreal Math Quebec Canada
PDF
No ratings yet
Engineering of Alphabets by Bahaa Dergham Montreal Math Quebec Canada
6 pages
Math Terms
PDF
100% (1)
Math Terms
19 pages
Phi and The Fibonacci Sequence
PDF
No ratings yet
Phi and The Fibonacci Sequence
16 pages
Prelim Reviewer
PDF
No ratings yet
Prelim Reviewer
4 pages
Assessment1 Hatap, J.N
PDF
No ratings yet
Assessment1 Hatap, J.N
7 pages
MODULE I - Learning Activity 2 - The Fibonacci Sequence
PDF
No ratings yet
MODULE I - Learning Activity 2 - The Fibonacci Sequence
3 pages
Krystal Fibonacci Spiral Separation
PDF
No ratings yet
Krystal Fibonacci Spiral Separation
7 pages
Sound Healing
PDF
No ratings yet
Sound Healing
20 pages
Theory of Architecture: Architectural Systems
PDF
No ratings yet
Theory of Architecture: Architectural Systems
11 pages