Python Homework 3, 4, & 5
Python Home work
data_list=[“And now here is my secret, a very simple secret: It is only with the heart that one can see rightly; what is essential is invisible to the eye.”,
“All grown-ups were once children… but only few of them remember it.”,
“People have forgotten this truth,\” the fox said. \”But you mustn’t forget it. You become responsible forever for what you’ve tamed. You’re responsible for your rose.”,
“It is the time you have wasted for your rose that makes your rose so important.”,
“The most beautiful things in the world cannot be seen or touched, they are felt with the heart.”,
“What makes the desert beautiful,’ said the little prince, ‘is that somewhere it hides a well…”,
“You – you alone will have the stars as no one else has them…In one of the stars I shall be living. In one of them I shall be laughing. And so it will be as if all the stars were laughing, when you look at the sky at night…You – only you – will have stars that can laugh.”,
“Well, I must endure the presence of a few caterpillars if I wish to become acquainted with the butterflies.”,
“You see, one loves the sunset when one is so sad.”,
“You’re beautiful, but you’re empty…One couldn’t die for you. Of course, an ordinary passerby would think my rose looked just like you. But my rose, all on her own, is more important than all of you together, since she’s the one I’ve watered. Since she’s the one I put under glass, since she’s the one I sheltered behind the screen. Since she’s the one for whom I killed the caterpillars (except the two or three butterflies). Since she’s the one I listened to when she complained, or when she boasted, or even sometimes when she said nothing at all. Since she’s my rose.”,
“If you love a flower that lives on a star, it is sweet to look at the sky at night. All the stars are a-bloom with flowers…”,
“And when your sorrow is comforted (time soothes all sorrows) you will be content that you have known me. You will always be my friend. You will want to laugh with me. And you will sometimes open your window, so, for that pleasure . . . And your friends will be properly astonished to see you laughing as you look up at the sky! Then you will say to them, ‘Yes, the stars always make me laugh!’ And they will think you are crazy. It will be a very shabby trick that I shall have played on you…”,
“You become responsible, forever, for what you have tamed.”,
“Of course I’ll hurt you. Of course you’ll hurt me. Of course we will hurt each other. But this is the very condition of existence. To become spring, means accepting the risk of winter. To become presence, means accepting the risk of absence.”,
“Where are the people?\” resumed the little prince at last. \”It’s a little lonely in the desert…\” \”It is lonely when you’re among people, too,\” said the snake.”,
“All men have stars, but they are not the same things for different people. For some, who are travelers, the stars are guides. For others they are no more than little lights in the sky. For others, who are scholars, they are problems… But all these stars are silent. You-You alone will have stars as no one else has them… In one of the stars I shall be living. In one of them I shall be laughing. And so it will be as if all the stars will be laughing when you look at the sky at night..You, only you, will have stars that can laugh! And when your sorrow is comforted (time soothes all sorrows) you will be content that you have known me… You will always be my friend. You will want to laugh with me. And you will sometimes open your window, so, for that pleasure… It will be as if, in place of the stars, I had given you a great number of little bells that knew how to laugh”,
“She cast her fragrance and her radiance over me. I ought never to have run away from her… I ought to have guessed all the affection that lay behind her poor little stratagems. Flowers are so inconsistent! But I was too young to know how to love her…”,
“A rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a cathedral.”,
“I did not know how to reach him, how to catch up with him… The land of tears is so mysterious.”,
“I remembered the fox. One runs the risk of crying a bit if one allows oneself to be tamed.”,
“When someone blushes, doesn’t that mean ‘yes’?”,
“You’re beautiful, but you’re empty. No one could die for you.”,
“In those days, I didn’t understand anything. I should have judged her according to her actions, not her words. She perfumed my planet and lit up my life. I should never have run away! I ought to have realized the tenderness underlying her silly pretensions. Flowers are so contadictory! But I was too young to know how to love her.”,
“I have lived a great deal among grown-ups. I have seen them intimately, close at hand. And that hasn’t much improved my opinion of them.”,
“Grown-ups love figures… When you tell them you’ve made a new friend they never ask you any questions about essential matters. They never say to you \”What does his voice sound like? What games does he love best? Does he collect butterflies? \” Instead they demand \”How old is he? How much does he weigh? How much money does his father make? \” Only from these figures do they think they have learned anything about him.”,
“The proof that the little prince existed is that he was charming, that he laughed, and that he was looking for a sheep. If anybody wants a sheep, that is a proof that he exists.”,
“No one is ever satisfied where he is.”,
“I was too young to know how to love her.”,
“I am who I am and I have the need to be.”,
“But the conceited man did not hear him. Conceited people never hear anything but praise.”,
“Men have no more time to understand anything. They buy things all ready made at the shops. But there is no shop anywhere where one can buy friendship, and so men have no friends any more. If you want a friend, tame me…”,
“For millions of years flowers have been producing thorns. For millions of years sheep have been eating them all the same. And it’s not serious, trying to understand why flowers go to such trouble to produce thorns that are good for nothing? It’s not important, the war between the sheep and the flowers? It’s no more serious and more important than the numbers that fat red gentleman is adding up? Suppose I happen to know a unique flower, one that exists nowhere in the world except on my planet, one that a little sheep can wipe out in a single bite one morning, just like that, without even realizing what he’d doing – that isn’t important? If someone loves a flower of which just one example exists among all the millions and millions of stars, that’s enough to make him happy when he looks at the stars. He tells himself ‘My flower’s up there somewhere…’ But if the sheep eats the flower, then for him it’s as if, suddenly, all the stars went out. And that isn’t important?”,
“I have always loved the desert. One sits down on a desert sand dune, sees nothing, hears nothing. Yet through the silence something throbs, and gleams…”,
“People have stars, but they aren’t the same. For travelers, the stars are guides. For other people, they’re nothing but tiny lights. And for still others, for scholars, they’re problems… But all those stars are silent stars. You, though, you’ll have stars like nobody else… since I’ll be laughing on one of them, for you it’ll be as if all the stars are laughing. You’ll have stars that can laugh!… and it’ll be as if I had given you, instead of stars, a lot of tiny bells that know how to laugh …”,
“What does tamed mean? It’s something that’s been too often neglected. It means to create ties.”,
“The only things you learn are the things you tame”,
“One runs the risk of weeping a little, if one lets himself be tamed.”,
“You’re not at all like my rose. You’re nothing at all yet. No one has tamed you and you haven’t tamed anyone. You’re the way my fox was. He was just a fox like a hundred thousand others. But I’ve made him my own and now he is unique in the world.”,
“I ought not to have listened to her,’ he confided to me one day. ‘One never ought to listen to the flowers. One should simply look at them and breathe their fragrance. Mine perfumed all my planet. But I did not know how to take pleasure in all her grace.”,
“You will have five hundred million little bells, and I shall have five hundred million springs of fresh water…”,
“…if you tame me, then we shall need each other. To me, you will be unique in all the world. To you, I shall be unique in all the world…if you tame me, it will be as if the sun came to shine on my life. I shall know the sound of a step that will be different from all the others. Other steps send me hurrying back underneath the ground. Yours will call me, like music, out of my burrow”,
“If you tame me, it would be as if the sun came to shine on my life.”,
“Men have no more time to understand anything. They buy ready-made things in the shops. But since there are no shops where you can buy friends, men no longer have any friends.”,
“All grown-ups were children first. (But few remember it).”,
“Of course, I love you,’ the flower said to him. ‘If you were not aware of it, it was my fault.”,
“The thing that is important is the thing that is not seen.”,
“It is much more difficult to judge oneself than to judge others.”,
“You know…my flower…I’m responsible for her. And she’s so weak! And so naive. She has four ridiculous thorns to defend her against the world…”,
“\”Ephemeral\” It means ‘which is in danger of speedy disappearance.”,
“He fell as gently as a tree falls. There was not even any sound..”,
“The house, the stars, the desert — what gives them their beauty is something that is invisible!”,
“\”My life is very monotonous,\” the fox said. \”I hunt chickens; men hunt me. All the chickens are just alike, and all the men are just alike. And, in consequence, I am a little bored.\””,
“Sometimes, there is no harm in putting off a piece of work until another day.”,
“Only the children know what they are looking for.”,
“Grown ups never understood anything by themselves. And it is rather tedious to have to explain things to them time and again”,
“It is much more difficult to judge oneself than to judge others. If you succeed in judging yourself rightly, then you are a man of true wisdom.”,
“Words are the source of misunderstandings.”,
“And the little prince broke into a lovely peal of laughter, which irritated me very much. I like my misfortunes to be taken seriously.”,
“\”What a queer planet!\” he thought. \”It is altogether dry, and altogether pointed, and altogether harsh and forbidding. And the people have no imagination. They repeat whatever one says to them . . . On my planet I had a flower; she always was the first to speak . . .”,
“I know a planet where there is a certain red-faced gentleman. He has never smelled a flower. He has never looked at a star. He has never loved any one. He has never done anything in his life but add up figures. And all day he says over and over, just like you: ‘I am busy with matters of consequence!’ And that makes him swell up with pride. But he is not a man – he is a mushroom!”,
“But if you tame me, my life will be filled with sunshine. I’ll know the sound of footsteps that will be different from all the rest. Others send me back underground. Yours will call me out of my burrow like music.”,
“I believe that for his escape he took advantage of the migration of a flock of wild birds.”,
“He had taken seriously words which were without importance, and it made him very unhappy.”,
“If you come at four in the afternoon, I’ll begin to be happy by three.”,
“One must require from each one the duty which each one can perform. Accepted authority rests first of all on reason.”,
“Straight ahead you can’t go very far.”,
“One sees clearly only with the heart. Anything essential is invisible to the eyes.”,
“I wonder if the stars are lit up so that each one of us can find her own star again.”,
“My drawing was not a picture of a hat. It was a picture of a boa constrictor digesting an elephant.”,
“To you I am just a fox, like a hundred thousand others, but if you tame me we shall need one another and I shall be unique to you in all the world.”,
“Don’t linger like this. You have decided to go away. Now go!”,
“But I, alas, do not know how to see sheep through the walls of boxes. Perhaps I am a little like the grown-ups. I have had to grow old.”,
“I remembered the fox. You risk tears if you let yourself be tamed.”,
“Wait for a time, exactly under the star. Then, if a little man appears who laughs, who has golden hair and refuses to answer questions, you will know who he is, If this should happen, please comfort me. Send me word that he has come back.”,
“If I am attempting to describe him, it is in order not to forget him. It is sad to forget a friend. Not every one has had a friend.”,
“The thing that is important is the thing that is not seen”,
“Nevertheless he is the only one of them all who does not seem to me ridiculous. Perhaps that is because he is thinking of something else besides himself.”,
“If someone loves a flower of which just one exists among all the millions and millions of stars, that’s enough to make him happy when he looks at the stars.”,
“If you want to build a ship, don’t drum up people to collect wood and don’t assign them tasks and work, but rather teach them to long for the endless immensity of the sea.”,
“Will you draw me a sheep?”,
“It’s good to have a friend. Even if you’re going to die.”,
“If you love a flower that lives on a star, then it’s good at night, to look up at the sky. All the stars are blossoming.”]
query=input(“query:”)
print(query)
for quote in data_list:
found_at = quote.find(query)
if( found_at >= 0):
print(“Found:”, “…”+quote[found_at:found_at+50], “…”)
—————————————————————————————————————————————
part A (submit as a separate program). Make the search case Insensitive, i.e. With the current program, the “Will” and “will” are searched as two different entities, see examples below. Modify program such, that all occurrences of the searched word will be found regardless of the case, i.e. the search for “will” or “Will” should return results containing all “will”, “Will”, “WILL”
part B (submit as a separate program). Allow multiple, not joined query terms. See example below, if I search for “this should happen” I get a result, however, if I search for “this happen” I get no results, because the current search implementation searched for exact string match. Modify the program such that each query term separated by the white spaces is searched. Only results containing ALL keywords should be returned.
part C (submit as a separate program). If not results found, print “No results found”. in the example above, if no results found, the program does not provide a good feedback to the user, please add a feedback message in the case when no results are found
part D (submit as a separate program): Introduce AND and OR operators for at least 2 keywords, ok to limit to only 1 operator (either AND used or OR used, ok if program doesn’t work well for combination of both or for more than 2 keywords):
a search query “love AND flower” should return only results containing both “love” and “flower”:
“If you love a flower that lives on a star, it is sweet to look at the sky at night. All the stars are a-bloom with flowers…”,
“Of course, I love you,’ the flower said to him. ‘If you were not aware of it, it was my fault.”
“If you love a flower that lives on a star, then it’s good at night, to look up at the sky. All the stars are blossoming.”
optional (ok if it is returned or not): “If someone loves a flower of which just one exists among all the millions and millions of stars, that’s enough to make him happy when he looks at the stars.”,
a search query “love OR flower” should return results containing either “love” or “flower”:
optional (ok if it is returned or not): “You see, one loves the sunset when one is so sad.”
“If you love a flower that lives on a star, it is sweet to look at the sky at night. All the stars are a-bloom with flowers…”
“Grown-ups love figures… When you tell them you’ve made a new friend they never ask you any questions about essential matters. They never say to you \”What does his voice sound like? What games does he love best? Does he collect butterflies? \” Instead they demand \”How old is he? How much does he weigh? How much money does his father make? \” Only from these figures do they think they have learned anything about him.”
“I was too young to know how to love her.”
optional (ok if it is returned or not):”I have always loved the desert. One sits down on a desert sand dune, sees nothing, hears nothing. Yet through the silence something throbs, and gleams…”
“Of course, I love you,’ the flower said to him. ‘If you were not aware of it, it was my fault.”,
optional (ok if it is returned or not):”And the little prince broke into a lovely peal of laughter, which irritated me very much. I like my misfortunes to be taken seriously.”
“If someone loves a flower of which just one exists among all the millions and millions of stars, that’s enough to make him happy when he looks at the stars.”,
“If you love a flower that lives on a star, then it’s good at night, to look up at the sky. All the stars are blossoming.”
optional (ok if it is returned or not):”For millions of years flowers have been producing thorns. For millions of years sheep have been eating them all the same. And it’s not serious, trying to understand why flowers go to such trouble to produce thorns that are good for nothing? It’s not important, the war between the sheep and the flowers? It’s no more serious and more important than the numbers that fat red gentleman is adding up? Suppose I happen to know a unique flower, one that exists nowhere in the world except on my planet, one that a little sheep can wipe out in a single bite one morning, just like that, without even realizing what he’d doing – that isn’t important? If someone loves a flower of which just one example exists among all the millions and millions of stars, that’s enough to make him happy when he looks at the stars. He tells himself ‘My flower’s up there somewhere…’ But if the sheep eats the flower, then for him it’s as if, suddenly, all the stars went out. And that isn’t important?”
“You know…my flower…I’m responsible for her. And she’s so weak! And so naive. She has four ridiculous thorns to defend her against the world…”
part E (submit as a separate program): Analyze the inputs and outputs from the program above, what happens if the user enters same keyword multiple times, ex: “flower AND flower”, does your program still search for each one? If yes, modify your program such that it does not search for repeated keywords. Also, ensure that the output quotes are only displayed once, i.e. there should be no repeating quotes in the output.
Python Homework 4
Program1:
Very frequently there is a need to monitor a presence of a file in some directory, this maybe needed for:
· Automated deployment jobs – every time a new bundle is uploaded, deploy it
· Synch processes – there are multiple clustered servers, and they need to have same files on them
· Error file – if file is ever present, then there is an error – send an email
write a program that will take a command line argument of full path and prints True if the file/directory at the provided location is present
Change program such that it runs indefinitely, monitoring a file/directory at a certain location
Program 2:
Modify the quote generator program such that if there are multiple quotes for the given author, instead of writing them out into the same file, the program instead creates a new file for each quote, hence if you have 3 quotes for an author, you would have 3 files in that author’s folder, named quote_1.txt, quote_2.txt, quote_3.txt. If the author has only 1 quote, then file can be named wither quote.txt or quote_1.txt
Program 3:
Use decorator function you created for the previous homework and estimate how much operation on a dictionary is faster(or slower) than operation on a shelve
Program 4:
Prompt user to enter a start path and file name, search recursively for the given file name starting at the given path, when file is found, display the full path to the file.
Python Homework 5
Program 1:
Use generator functions to create your own version of range function, call it my_range. Do not use the python’s range function in the code.
Program 2:
We have bunnies standing in a line, numbered 1, 2, … The odd bunnies (1, 3, ..) have the normal 2 ears. The even bunnies (2, 4, ..) we’ll say have 3 ears, because they each have a raised foot. Recursively return the number of “ears” in the bunny line 1, 2, … n (without loops or multiplication).
bunnyEars2(0) → 0
bunnyEars2(1) → 2
bunnyEars2(2) → 5
Use pytest to validate the correctness of the function
Program 3:
The program below gives elapsed execution time in seconds of the print statement
Create a decorator function that will take any function, with any number of arguments and print the time it takes to execute it
Program 4:
You are working on a “secure cloud data transfer” team. You are tasked with creating a mechanism for encrypting data prior to transfer and decrypting it once the transfer is complete. Write two decorator functions encrypt and decrypt . When applied as a decorator, the encrypt function will encrypt the returning string (assume it is always a string) and decrypt function will decrypt the encrypted string back to its original value.
The encryption logic does not matter (just don’t leave the string “as is”); for example, a reverse of the string or shifting characters is sufficient (you do not need to have the encryption work perfectly well)
if you like to do more research and use some real crypto algorithms, you may do so for up to 3.3 (double) additional points on the homework. You can use
this resource
for the research:
www.tutorialspoint.com/cryptography_with_python/cryptography_with_python_quick_guide.htm
If you need to use a common key for encryptor and decryptor, you can either duplicate the key in each function’s declaration or use the global variable or any other method, ex: env vars (your approach will not be penalized, however it would be nice if you discuss con’s and pro’s of your implementation)
Use pytest to ensure the decrypted string matches the original string.
program 1:
Write a function that converts temperature from Fahrenheit to Celsius using formula
Tc=(5/9)*(Tf-32)
To test your answer, 68F = 20C
program 2:
Write a function count_frequency that takes a list of words as an argument, counts how many times each word appears in the list, and then returns this frequency listing as a Python dictionary
Sample function call and output:
mylist=[“one”, “two”,”eleven”, “one”, “three”, “two”, “eleven”, “three”, “seven”, “eleven”]
print(count_frequency(mylist))
{‘seven’: 1, ‘one’: 2, ‘eleven’: 3, ‘three’: 2, ‘two’: 2}
additional independent research, understand how
Counter
can be used. You do not need to submit anything, but there will be a question in the next week’s quiz covering this topic
program 3:
leetcode two sum: https://leetcode.com/problems/two-sum/
You need to build a URL shortener, similar to https://bitly.com/
On the bottom of the bitly URL above, you can paste a long URL and it will generate a short URL
For this program you will need to write two functions:
shorten_url function: takes a long URL and generates and returns a short URL – the short URL doesn’t need to match the one on the bitly page, it should be just a shorter than the original URL
get_original_url function: takes a short URL as input and returns original long URL, if the short URL not found, return “HTTP 404” string instead
You will need to come up with the URL shortening mechanism, it is up to you what method you will use, but you must go through the following options and discuss in the comments of your program submission the pro’s and con’s of each of these methods. The correctness of your reasoning will not be graded. As you discuss pro’s and con’s think through chances of possible clashes of the shortened URL’s, how many URL’s will you be able to shorten total using the method and how much memory you think you will need to store all the short and matching long URL’s. You can make and state your assumptions in the comments as well, for example you may assume an average length of a long URL to be 500 characters
1. uuid: https://docs.python.org/3/library/uuid.html
2. timestamp: https://realpython.com/python-time-module/#python-time-in-seconds-as-a-floating-point-number
3. MD5 hash: https://www.geeksforgeeks.org/md5-hash-python/
4. Another short string generation mechanism either your own or some other than above 3 python functions
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.