Question

python question lets say you had a string that was returned from a block of code...

python question

lets say you had a string that was returned from a block of code that converted it from letters to numbers.

for example, the user input was "hi", the code converted it into "89" as a string

with a dictionary how could you take that "89" and go back into hi again?

lets say the dictionary was keys and values of keys = alphabet and values = numbers

the output would be back at "hi" again

Convert into numbers

Homework Answers

Answer #1

Code :

===================================================

dict1 ={"Hi":89, "Bye":52}
def NumToText(a):
  
key_list = list(dict1.keys())
val_list = list(dict1.values())
print(key_list[val_list.index(a)])

def TextToNum(a):
print(dict1[a])

  
print("====Menu====== ")
print("1. Number to Text")
print("2. Text to Number")
n=int(input("Enter Your Choice :"))
if n==1:
a=int(input("Enter a Number (Ex: 89): "))
NumToText(a)
else:
a=input("Enter a Text (Ex: Hi): ")
TextToNum(a)

  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python program to ask user input of a string, then ask user input of...
Write a Python program to ask user input of a string, then ask user input of what letters they want to remove from the string. User can either put in "odd", "even" or a number "n" that is greater than 2. When user input "odd", it will remove the characters which have odd numbers in the sequence of the string. When user input "even", it will remove the characters which have even numbers in the sequence of the string. When...
Python Write the contents of the function below. It should build a dictionary with keys and...
Python Write the contents of the function below. It should build a dictionary with keys and values. For each such entry, it must enter two rows from the keyboard. The first line should constitute the key to be stored in a form with only capital letters. The user enters the value on the next row. This should be stored as an integer. If you enter a blank line as the key, the lock should end and the dictionary is returned....
How do you code in Java a method (lets say its called PosOddAverage) that: - Takes...
How do you code in Java a method (lets say its called PosOddAverage) that: - Takes an array of doubles as input - Prints the avearge of positive odd numbers in the array - Prints 'ERROR' for empty input array An Example: Input: [1.2,1.5,0.0,-2.3,3.5,7.1,-1.3] Output: 4.03333333 Thanks :)
Python Regular Expressions problem: How do you get string data from file of say rows of...
Python Regular Expressions problem: How do you get string data from file of say rows of IP address and city location values obtained from re.finditer patterns to appear in the same dictionary? for example: text file has 100.200.10.255 New York City 10. 16. 25.254 Los Angeles segment of code includes for item in re.finditer(the_two_patterns, text_file, re.MULTILINE): print (item.groupdict()) result is below that I am getting {‘IP’: ‘100.200.10.255’, ‘city’: None} {‘IP’: None, ‘city’: ‘New York City’} {‘IP’: ‘10.16.25.254’, ‘city’: None} {IP’:...
How would I solve these python problems? A) File Display Download the file from here named...
How would I solve these python problems? A) File Display Download the file from here named numbers.txt . Write a program that displays all of the numbers in the file. numbers.txt contains 22 14 -99 AB B) Error Check Float Input When you want an int input you can check the input using the string isdigit() method. However, there is no comparable check for float. Write a program that asks the user to enter a float and uses a try-except...
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression Evaluator as described in section 7-3b of the book. The program should ask the user for a string that contains a Postfix Expression. It should then use the string's split function to create a list with each token in the expression stored as items in the list. Now, using either the stack classes from 7.2 or using the simulated stack functionality available in a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT