Question

PYTHON programming assignment Suppose you are working at a lab and you have been asked to...

PYTHON programming assignment

Suppose you are working at a lab and you have been asked to make a dictionary of raw data [of numbers and texts attached to each other]. The keys in the dictionary will be the texts, and the numbers are their values. Needs multiple line input.

Sample input:

2
electron1 gamma5 proton43 boson98
cat1 ray5 elec9 pion7

Sample output:

{'electron':1, 'gamma':5, 'proton':43, 'boson':98}
{'cat':1, 'ray':5, 'elec':9, 'pion':7}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
n = int(input())
for i in range(n):
    result = {}
    s = input()
    for x in s.split(" "):
        k = len(x)-1
        number = ''
        while(x[k].isdigit()):
            number=x[k]+number
            k = k - 1
        result[x[:k+1]] = int(number)
    print(result)

Add a comment
Know the answer?
Add Answer to:
PYTHON programming assignment Suppose you are working at a lab and you have been asked to...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Could anyone please help with this Python code assignment? In this programming assignment you are to...

    Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...

  • need help with python program The objectives of this lab assignment are as follows: . Input...

    need help with python program The objectives of this lab assignment are as follows: . Input data from user Perform several different calculations Implement conditional logic in loop • Implement logic in functions Output information to user Skills Required To properly complete this assignment, you will need to apply the following skills: . Read string input from the console and convert input to required numeric data-types Understand how to use the Python Modulo Operator Understand the if / elif /...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • JAVA Programming Assignment: You run four computer labs. Each lab contains computer stations that are numbered...

    JAVA Programming Assignment: You run four computer labs. Each lab contains computer stations that are numbered as shown in the table below:- Lab Number   Computer Station Numbers 1   1-5 2   1-6 3   1-4 4   1-3 Each user has a unique five-digit ID Number. Whenever a user logs on, the user's ID, Lab Number, and the computer station are transmitted to your station. For example, if user 49193 logs onto station 2 in Lab 3, your system receives (49193, 2, 3)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT