├── bmr.py ├── class.py ├── file.txt ├── files.py ├── functions.py ├── hello_world.py ├── loops.py ├── re.py ├── re_files.py ├── re_notes.py ├── scope.py ├── shakespeare.txt ├── special_classes.py ├── tuples.py └── using_modules.py /bmr.py: -------------------------------------------------------------------------------- 1 | # Basal Metabolic Rate Calculator 2 | 3 | weight = int(input("Enter your weight in KG: \n")) 4 | height = int(input("Enter your height in cm: \n")) 5 | age = int(input("Enter your age in years: \n")) 6 | isMale = str(input("Are you male? (y/n)")) 7 | 8 | if isMale == "y": 9 | isMale = True 10 | elif isMale == "n": 11 | isMale = False 12 | else: 13 | print("Error") 14 | quit() 15 | 16 | 17 | 18 | # Mifflin St. Jeor Equation for males 19 | if isMale: 20 | bmr = 66.5 + (13.75 * weight) + (5 * height) - (6.755 * age) 21 | else: 22 | bmr = 655.1 + (9.6 * weight) + (1.8 * height) - (4.7 * age) 23 | 24 | bmr = round(bmr) 25 | print(bmr) 26 | -------------------------------------------------------------------------------- /class.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | 3 | age = 18 4 | 5 | def name(self, name): 6 | return list(name) 7 | -------------------------------------------------------------------------------- /file.txt: -------------------------------------------------------------------------------- 1 | This is some text!! 2 | This is some text!! 3 | This is some text!! 4 | This is some text!! 5 | This is some text!! 6 | This is some text!! 7 | This is some text!! 8 | This is some text!! 9 | This is some text!! 10 | This is some text!! 11 | This is some text!! 12 | This is some text!! 13 | This is some text!! 14 | This is some text!! 15 | This is some text!! 16 | This is some text!! 17 | This is some text!! 18 | This is some text!! 19 | This is some text!! 20 | This is some text!! 21 | -------------------------------------------------------------------------------- /files.py: -------------------------------------------------------------------------------- 1 | text = 'This is some text!!\n' 2 | 3 | file = open('file.txt', 'a') 4 | for each in range(10): 5 | file.write(text) 6 | 7 | file.close() 8 | -------------------------------------------------------------------------------- /functions.py: -------------------------------------------------------------------------------- 1 | def add(): 2 | return 2 + 3 3 | 4 | def multiply(): 5 | return 2 * 3 6 | 7 | def cube(): 8 | return 2 ** 3 9 | 10 | def square_area(side_length=4): 11 | area = side_length * 2 12 | return area 13 | 14 | def rectangle_perimeter(width, height): 15 | perimeter = width * 2 + height * 2 16 | return perimeter 17 | -------------------------------------------------------------------------------- /hello_world.py: -------------------------------------------------------------------------------- 1 | print("Hello World!") 2 | -------------------------------------------------------------------------------- /loops.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | # For loop 4 | numbers = range(1,11) 5 | 6 | for number in numbers: 7 | print(number) 8 | """ 9 | 10 | # While loop 11 | 12 | count = 0 13 | 14 | while count < 5: 15 | print(count) 16 | count += 1 17 | -------------------------------------------------------------------------------- /re.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | myString = 'Send an email from this@email.com to test@user.com 34 times.' 4 | 5 | result = re.findall('\S+@\S+', myString) 6 | print(result) 7 | -------------------------------------------------------------------------------- /re_files.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = open('shakespeare.txt') 4 | 5 | for line in text: 6 | line = line.rstrip() 7 | if re.search('^[A-Z]{3,6}.*$', line): 8 | print(line) 9 | 10 | # Regular Expressions 11 | '^[A-Z]{3,6}.*$' 12 | '^[A-Z]{6}.*$' 13 | '^[A-Z]{6}.+$' 14 | '^[A-Z]{5}.+$' 15 | '^A.+again.$' 16 | '^T.+t.+!$' 17 | -------------------------------------------------------------------------------- /re_notes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Regular Expressions 3 | 4 | ^ Start 5 | $ Stop 6 | . Any character 7 | * Match one character 0+ times 8 | + Match one character 1+ times 9 | ? Non-greedy 10 | \s Whitespace 11 | \S Non-whitespace 12 | [abc] Match one character in the specified set 13 | [^abc] Match one character not in the specified set 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | """ 30 | -------------------------------------------------------------------------------- /scope.py: -------------------------------------------------------------------------------- 1 | 2 | x = "John" 3 | 4 | 5 | def scope(x): 6 | 7 | print(x) 8 | 9 | scope(x) 10 | -------------------------------------------------------------------------------- /shakespeare.txt: -------------------------------------------------------------------------------- 1 | Romeo and Juliet 2 | Act 2, Scene 2 3 | 4 | SCENE II. Capulet's orchard. 5 | 6 | Enter ROMEO 7 | 8 | ROMEO 9 | 10 | He jests at scars that never felt a wound. 11 | JULIET appears above at a window 12 | 13 | But, soft! what light through yonder window breaks? 14 | It is the east, and Juliet is the sun. 15 | Arise, fair sun, and kill the envious moon, 16 | Who is already sick and pale with grief, 17 | That thou her maid art far more fair than she: 18 | Be not her maid, since she is envious; 19 | Her vestal livery is but sick and green 20 | And none but fools do wear it; cast it off. 21 | It is my lady, O, it is my love! 22 | O, that she knew she were! 23 | She speaks yet she says nothing: what of that? 24 | Her eye discourses; I will answer it. 25 | I am too bold, 'tis not to me she speaks: 26 | Two of the fairest stars in all the heaven, 27 | Having some business, do entreat her eyes 28 | To twinkle in their spheres till they return. 29 | What if her eyes were there, they in her head? 30 | The brightness of her cheek would shame those stars, 31 | As daylight doth a lamp; her eyes in heaven 32 | Would through the airy region stream so bright 33 | That birds would sing and think it were not night. 34 | See, how she leans her cheek upon her hand! 35 | O, that I were a glove upon that hand, 36 | That I might touch that cheek! 37 | 38 | JULIET 39 | 40 | Ay me! 41 | 42 | ROMEO 43 | 44 | She speaks: 45 | O, speak again, bright angel! for thou art 46 | As glorious to this night, being o'er my head 47 | As is a winged messenger of heaven 48 | Unto the white-upturned wondering eyes 49 | Of mortals that fall back to gaze on him 50 | When he bestrides the lazy-pacing clouds 51 | And sails upon the bosom of the air. 52 | 53 | JULIET 54 | 55 | O Romeo, Romeo! wherefore art thou Romeo? 56 | Deny thy father and refuse thy name; 57 | Or, if thou wilt not, be but sworn my love, 58 | And I'll no longer be a Capulet. 59 | 60 | ROMEO 61 | 62 | [Aside] Shall I hear more, or shall I speak at this? 63 | 64 | JULIET 65 | 66 | 'Tis but thy name that is my enemy; 67 | Thou art thyself, though not a Montague. 68 | What's Montague? it is nor hand, nor foot, 69 | Nor arm, nor face, nor any other part 70 | Belonging to a man. O, be some other name! 71 | What's in a name? that which we call a rose 72 | By any other name would smell as sweet; 73 | So Romeo would, were he not Romeo call'd, 74 | Retain that dear perfection which he owes 75 | Without that title. Romeo, doff thy name, 76 | And for that name which is no part of thee 77 | Take all myself. 78 | 79 | ROMEO 80 | 81 | I take thee at thy word: 82 | Call me but love, and I'll be new baptized; 83 | Henceforth I never will be Romeo. 84 | 85 | JULIET 86 | 87 | What man art thou that thus bescreen'd in night 88 | So stumblest on my counsel? 89 | 90 | ROMEO 91 | 92 | By a name 93 | I know not how to tell thee who I am: 94 | My name, dear saint, is hateful to myself, 95 | Because it is an enemy to thee; 96 | Had I it written, I would tear the word. 97 | 98 | JULIET 99 | 100 | My ears have not yet drunk a hundred words 101 | Of that tongue's utterance, yet I know the sound: 102 | Art thou not Romeo and a Montague? 103 | 104 | ROMEO 105 | 106 | Neither, fair saint, if either thee dislike. 107 | 108 | JULIET 109 | 110 | How camest thou hither, tell me, and wherefore? 111 | The orchard walls are high and hard to climb, 112 | And the place death, considering who thou art, 113 | If any of my kinsmen find thee here. 114 | 115 | ROMEO 116 | 117 | With love's light wings did I o'er-perch these walls; 118 | For stony limits cannot hold love out, 119 | And what love can do that dares love attempt; 120 | Therefore thy kinsmen are no let to me. 121 | 122 | JULIET 123 | 124 | If they do see thee, they will murder thee. 125 | 126 | ROMEO 127 | 128 | Alack, there lies more peril in thine eye 129 | Than twenty of their swords: look thou but sweet, 130 | And I am proof against their enmity. 131 | 132 | JULIET 133 | 134 | I would not for the world they saw thee here. 135 | 136 | ROMEO 137 | 138 | I have night's cloak to hide me from their sight; 139 | And but thou love me, let them find me here: 140 | My life were better ended by their hate, 141 | Than death prorogued, wanting of thy love. 142 | 143 | JULIET 144 | 145 | By whose direction found'st thou out this place? 146 | 147 | ROMEO 148 | 149 | By love, who first did prompt me to inquire; 150 | He lent me counsel and I lent him eyes. 151 | I am no pilot; yet, wert thou as far 152 | As that vast shore wash'd with the farthest sea, 153 | I would adventure for such merchandise. 154 | 155 | JULIET 156 | 157 | Thou know'st the mask of night is on my face, 158 | Else would a maiden blush bepaint my cheek 159 | For that which thou hast heard me speak to-night 160 | Fain would I dwell on form, fain, fain deny 161 | What I have spoke: but farewell compliment! 162 | Dost thou love me? I know thou wilt say 'Ay,' 163 | And I will take thy word: yet if thou swear'st, 164 | Thou mayst prove false; at lovers' perjuries 165 | Then say, Jove laughs. O gentle Romeo, 166 | If thou dost love, pronounce it faithfully: 167 | Or if thou think'st I am too quickly won, 168 | I'll frown and be perverse an say thee nay, 169 | So thou wilt woo; but else, not for the world. 170 | In truth, fair Montague, I am too fond, 171 | And therefore thou mayst think my 'havior light: 172 | But trust me, gentleman, I'll prove more true 173 | Than those that have more cunning to be strange. 174 | I should have been more strange, I must confess, 175 | But that thou overheard'st, ere I was ware, 176 | My true love's passion: therefore pardon me, 177 | And not impute this yielding to light love, 178 | Which the dark night hath so discovered. 179 | 180 | ROMEO 181 | 182 | Lady, by yonder blessed moon I swear 183 | That tips with silver all these fruit-tree tops-- 184 | 185 | JULIET 186 | 187 | O, swear not by the moon, the inconstant moon, 188 | That monthly changes in her circled orb, 189 | Lest that thy love prove likewise variable. 190 | 191 | ROMEO 192 | 193 | What shall I swear by? 194 | 195 | JULIET 196 | 197 | Do not swear at all; 198 | Or, if thou wilt, swear by thy gracious self, 199 | Which is the god of my idolatry, 200 | And I'll believe thee. 201 | 202 | ROMEO 203 | 204 | If my heart's dear love-- 205 | 206 | JULIET 207 | 208 | Well, do not swear: although I joy in thee, 209 | I have no joy of this contract to-night: 210 | It is too rash, too unadvised, too sudden; 211 | Too like the lightning, which doth cease to be 212 | Ere one can say 'It lightens.' Sweet, good night! 213 | This bud of love, by summer's ripening breath, 214 | May prove a beauteous flower when next we meet. 215 | Good night, good night! as sweet repose and rest 216 | Come to thy heart as that within my breast! 217 | 218 | ROMEO 219 | 220 | O, wilt thou leave me so unsatisfied? 221 | 222 | JULIET 223 | 224 | What satisfaction canst thou have to-night? 225 | 226 | ROMEO 227 | 228 | The exchange of thy love's faithful vow for mine. 229 | 230 | JULIET 231 | 232 | I gave thee mine before thou didst request it: 233 | And yet I would it were to give again. 234 | 235 | ROMEO 236 | 237 | Wouldst thou withdraw it? for what purpose, love? 238 | 239 | JULIET 240 | 241 | But to be frank, and give it thee again. 242 | And yet I wish but for the thing I have: 243 | My bounty is as boundless as the sea, 244 | My love as deep; the more I give to thee, 245 | The more I have, for both are infinite. 246 | 247 | Nurse calls within 248 | 249 | I hear some noise within; dear love, adieu! 250 | Anon, good nurse! Sweet Montague, be true. 251 | Stay but a little, I will come again. 252 | Exit, above 253 | 254 | ROMEO 255 | 256 | O blessed, blessed night! I am afeard. 257 | Being in night, all this is but a dream, 258 | Too flattering-sweet to be substantial. 259 | 260 | Re-enter JULIET, above 261 | 262 | JULIET 263 | 264 | Three words, dear Romeo, and good night indeed. 265 | If that thy bent of love be honourable, 266 | Thy purpose marriage, send me word to-morrow, 267 | By one that I'll procure to come to thee, 268 | Where and what time thou wilt perform the rite; 269 | And all my fortunes at thy foot I'll lay 270 | And follow thee my lord throughout the world. 271 | 272 | Nurse 273 | 274 | [Within] Madam! 275 | 276 | JULIET 277 | 278 | I come, anon.--But if thou mean'st not well, 279 | I do beseech thee-- 280 | 281 | Nurse 282 | [Within] Madam! 283 | 284 | JULIET 285 | 286 | By and by, I come:-- 287 | To cease thy suit, and leave me to my grief: 288 | To-morrow will I send. 289 | 290 | ROMEO 291 | 292 | So thrive my soul-- 293 | 294 | JULIET 295 | 296 | A thousand times good night! 297 | Exit, above 298 | 299 | ROMEO 300 | 301 | A thousand times the worse, to want thy light. 302 | Love goes toward love, as schoolboys from 303 | their books, 304 | But love from love, toward school with heavy looks. 305 | Retiring 306 | 307 | Re-enter JULIET, above 308 | 309 | JULIET 310 | 311 | Hist! Romeo, hist! O, for a falconer's voice, 312 | To lure this tassel-gentle back again! 313 | Bondage is hoarse, and may not speak aloud; 314 | Else would I tear the cave where Echo lies, 315 | And make her airy tongue more hoarse than mine, 316 | With repetition of my Romeo's name. 317 | 318 | ROMEO 319 | 320 | It is my soul that calls upon my name: 321 | How silver-sweet sound lovers' tongues by night, 322 | Like softest music to attending ears! 323 | 324 | JULIET 325 | 326 | Romeo! 327 | 328 | ROMEO 329 | 330 | My dear? 331 | 332 | JULIET 333 | 334 | At what o'clock to-morrow 335 | Shall I send to thee? 336 | 337 | ROMEO 338 | 339 | At the hour of nine. 340 | 341 | JULIET 342 | 343 | I will not fail: 'tis twenty years till then. 344 | I have forgot why I did call thee back. 345 | 346 | ROMEO 347 | 348 | Let me stand here till thou remember it. 349 | 350 | JULIET 351 | 352 | I shall forget, to have thee still stand there, 353 | Remembering how I love thy company. 354 | 355 | ROMEO 356 | 357 | And I'll still stay, to have thee still forget, 358 | Forgetting any other home but this. 359 | 360 | JULIET 361 | 362 | 'Tis almost morning; I would have thee gone: 363 | And yet no further than a wanton's bird; 364 | Who lets it hop a little from her hand, 365 | Like a poor prisoner in his twisted gyves, 366 | And with a silk thread plucks it back again, 367 | So loving-jealous of his liberty. 368 | 369 | ROMEO 370 | 371 | I would I were thy bird. 372 | 373 | JULIET 374 | 375 | Sweet, so would I: 376 | Yet I should kill thee with much cherishing. 377 | Good night, good night! parting is such 378 | sweet sorrow, 379 | That I shall say good night till it be morrow. 380 | 381 | Exit above 382 | 383 | ROMEO 384 | 385 | Sleep dwell upon thine eyes, peace in thy breast! 386 | Would I were sleep and peace, so sweet to rest! 387 | Hence will I to my ghostly father's cell, 388 | His help to crave, and my dear hap to tell. 389 | 390 | Exit 391 | -------------------------------------------------------------------------------- /special_classes.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | 3 | def __init__(self, name, species): 4 | print("THIS CAME FROM THE INIT METHOD") 5 | self.name = name 6 | self.species = species 7 | 8 | def getName(self): 9 | return self.name 10 | 11 | def getSpecies(self): 12 | return self.species 13 | 14 | def __del__(self): 15 | print("THIS CAME FROM THE DEL METHOD") 16 | 17 | 18 | class FourLegs: 19 | def hasLegs(self): 20 | return 4 21 | 22 | 23 | class Dog(Animal, FourLegs): 24 | def __init__(self, name, isBig): 25 | Animal.__init__(self, name, "Dog") 26 | self.isBig = isBig 27 | 28 | def getName(self): 29 | return self.name, self.species, self.isBig 30 | -------------------------------------------------------------------------------- /tuples.py: -------------------------------------------------------------------------------- 1 | 2 | # List 3 | numbers = [1,2,3,4,5] 4 | 5 | # Tuple 6 | squares = (1,4,16,25,36) 7 | 8 | 9 | # Variable unpacking 10 | a,b,c = [1,2,3] 11 | print(a,b,c) 12 | 13 | 14 | x = (1,) 15 | y = (1,2) 16 | z = (1,2,3) 17 | print(x,y,z) 18 | -------------------------------------------------------------------------------- /using_modules.py: -------------------------------------------------------------------------------- 1 | import math 2 | import functions 3 | 4 | print(math.floor(3.7)) 5 | 6 | for each in range(1,11): 7 | print(functions.square_area(each)) 8 | --------------------------------------------------------------------------------