Python Forum
I need help for tomorrow please!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help for tomorrow please!
#1
4.
a. Create a dictionary named d1, which has three key-value pairs, so that there is one key of each data type: str, int, float.
b. Create an empty dictionary named d2
c. Go in a loop on all keys of d1, and insert them as values into d2. The keys of d2 will be the values from d1 (the inversion of keys and values)
d. The action may fail. If it fails, try to understand when the operation will fail and when it will succeed.

5.
a. Write a function named build_encrypt_code. The function builds an encryption dictionary that consists of hundreds as a key and a number as a value. For example:
{'a': 7, 'b': 1, 'c': 6, 'd': 0, 'e': 5, 'f' I ': 2,' j ': 8}
b. Write a punctuation called encrypt. The function accepts the dictionary from a and a one-word string, and encrypts the string according to the dictionary. If the letter does not exist in the dictionary, write it without encryption. Big and small letters are translated in the same way. For example, the letters A and A will be paired to number 7.
c. Write a master program that asks the user for a string and uses both functions to encrypt the string. The program prints the encrypted string.


1. Write a program that asks the user for a file name (including its path). The program will ask the user for 5 sentences and write them down to the group.

2. Write a program that prints random numbers into a file named numbers.txt. Each random number is in the range between 1 and 500. The user determines how many such numbers should be printed to a file. To generate numbers, ranges in the range between 1 and 500 record the following commands:

Import random
Random.randint (1,500)

3. Create a file named file1.txt that contains the following sentences:

Python is a great language.
I love python.
I thik Java is better.
When is the next python lesson? I simply can not miss it!
\ Write a program that reads all rows to a list named list1 (each line will be inserted as an item into list1). Go to the list and remove any entries that do not have the word Python (regardless of the uppercase or lowercase letter).
If you have to remove even one line, add the line to this file: This file is corrupt.
Reply
#2
Thank you for sharing your homework, the forum can assist on parts your are stuck with but cannot do your homework for you.
When you get stuck, please post a minimal code sample (in python code tags) for the specific part your stuck on, explain what you expect to happen and what is actually happening and any errors received in error tags.
If someone can they will then assist you.
Reply
#3
I could not solve anything I tried and I was present at the university class because of this I ask for help
If anyone can help me it will make me happy
Thank you and good day
Reply
#4
We will be happy to help, but you need to help us to help you, if you don't show what your stuck with we cant help you to get unstuck.
Reply
#5
I really tried for a week and could not understand the material
I really need your help and then I can understand the code through the code
Thank you very much appreciate it
Reply
#6
You must have lots of code after a week, show us the bits of it that you don't understand.
Explain what part your stuck with , what you expect it to do and what it actually does, also show any error trace backs you get.
Please put all the code and errors in their appropriate code tags.
Reply
#7
I tried 4
d = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
d2 = {}
result = {k: d2.get(v) for k, v in d1.items()}
Reply
#8
For 4a, your dictionary should be named d1, not d. Also, all the keys in d are strings. Some of them need to be ints and floats. Since all of your values are ints, it should be easy for you to make an int key. Floats are just numbers with a decimal, like 2.71818281828.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#9
once you correct the dict d1
Sounds more like you should just do a normal loop
for key, value in d1.items():
and then inside the loop add to the dict d2 the value as the key and the key as the value.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can anyone help me there? I have this due tomorrow and I'm stuck with no one to talk rarefaction 1 2,310 Sep-09-2020, 07:05 AM
Last Post: DPaul
  really need assistance with this assignment ASAP due tomorrow mohamedhadi02 8 3,522 Jun-21-2020, 09:16 AM
Last Post: mohamedhadi02

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020