-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_Basics_Exercises.py
More file actions
130 lines (90 loc) · 2.66 KB
/
Python_Basics_Exercises.py
File metadata and controls
130 lines (90 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 1. Simple Message
name: str = "My name is Memoona Zahur."
print(name)
# 2. Simple Messages
introduction: str = "My name is Memoona Zahur."
print(introduction)
introduction = "I am a student of BSCS"
print(introduction)
# 3. Personal Message
person_name: str = "Mona"
print(f"Hello {person_name}, would you like to learn some Python today?")
# 4. Name Cases
name = "meMOONa zaHuR"
print(name.lower())
print(name.upper())
print(name.title())
# 5. Famous Quote
quote = "The only way to do great work is to love what you do."
author = "Steve Jobs"
print(f'{author} once said, "{quote}"')
# 6. Famous Quote 2
famous_person = "Ayn Rand"
message = f'{famous_person} once said, "A creative man is motivated by the desire to achieve, not by the desire to beat others."'
print(message)
# 7. Stripping Names
name = " \n\tMemoona Zahur \t\n"
print(name)
print("The name after lstrip():", name.lstrip())
print("The name after rstrip():", name.rstrip())
print("The name after strip():", name.strip())
# 8. Variable Sum
x: int = 5
y: int = 10
z: int = 15
sum = x+y+z
print(f"The sum of {x}, {y} and {z} is: {sum}")
# 9. Variable Swap
a: int = 5
b: int = 7
print(f"""Before Swapping:
The value of a is: {a}
The value of b is: {b}""")
a, b = b, a
print(f"""After Swapping:
The value of a is: {a}
The value of b is: {b}""")
# 10. Favorite Color
favorite_color: str = "Black"
print(f"My favorite color is: {favorite_color}")
color = favorite_color
print(f"I like {color} color.")
# 11. Changing Pet Name
pet_name = "Buddy"
pet_name = "Max"
print(f"My pet's new name is: {pet_name}")
# 12. Observing Name Error
weather = "Sunshine"
print(weather)
# print(sunshine) # This will cause a Name Error
# 13. Reassigning Score
score = 100
print(f"The initial score is: {score}")
score = 500
print(f"The new score is: {score}")
# 14. City Name
city: str = "Lahore"
print(f"My favorite city is: {city}")
# 15. Title Case Text
text = "python programming"
print(f"In title case: {text.title()}")
# 16. Lowercase Conversion
language: str = "PYthOn pROGraMmING"
print(f"In lower case: {language.lower()}")
# 17. Uppercase Conversion
language = "PyThon progRaMMing"
print(f"In upper case: {text.upper()}")
# 18. Current Temperature
temperature = 25
print(f"The current temperature is {temperature} degrees.")
# 19. Printing a Poem
poem = """Let me but do my work from day to day,
In field or forest, at the desk or loom,
In roaring market-place or tranquil room;
Let me but find it in my heart to say,
When vagrant wishes beckon me astray,
"This is my work; my blessing, not my doom;
Of all who live, I am the one by whom
This work can best be done in the right way."
"""
print(poem)