'How to accept multiline input from user and compare input to values to return a specific output in python?
I would like for users to be able to enter amino acid mutations in the format:
A78K
E45N
R129L
The program should then read the input to extract only the beginning and last letter. The input includes the numbers because this is a common mutation format, but is not necessary to determine the output and so should be ignored.
Next, the letter pairs for each line (i.e. A K, E N, R L) need to be compared to a list of known values where (A K = 27, E N = 85, R L = 134, etc.). The order of the letters does not matter (A K and K A = 27).
The result should be an output with the score in the same order as the inputs:
27
85
134
So far, I have this:
print("Enter your content. Ctrl-D or Ctrl-Z ( windows ) to save it.")
contents = []
while True:
try:
line = input()
except EOFError:
break
contents.append(line)
However, this does not work because users may need the calculations for hundreds of mutations, but this code requires users to input each line manually. I would like them to be able to copy and paste from an Excel or text file with each mutation on a separate line and paste it into the input area. It would also be preferred if the user did not need to press control+D to stop the input.
I also am a bit confused on how to compare an input to a key,value pair and return a particular value.
Any help would be greatly appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
