Python Forum
Problem using input in Dictionary.. Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using input in Dictionary.. Help
#2
You are overwriting weight for each aa in the input and calculating the sum of an int
so either:
prot_weight = {'A':89, 'V':117, 'L':131, 'I':131, 'P':115, 'F':165, 'W':204,
               'M':149, 'G':75, 'S':105, 'C':121, 'T':119, 'Y':181, 'N':132, 
               'Q':146, 'D':133, 'E':147, 'K':146, 'R':174, 'H':155}
prot_sequence = input('please write the amino acid sequence = ')
weight = 0
for aa in prot_sequence:
    weight += prot_weight[aa]
print(weight)
or do it the pythonic way:
prot_weight = {'A':89, 'V':117, 'L':131, 'I':131, 'P':115, 'F':165, 'W':204,
               'M':149, 'G':75, 'S':105, 'C':121, 'T':119, 'Y':181, 'N':132, 
               'Q':146, 'D':133, 'E':147, 'K':146, 'R':174, 'H':155}

prot_sequence = input('please write the amino acid sequence = ')
weight = sum(prot_weight[character] for character in prot_sequence)
print(weight)
Reply


Messages In This Thread
RE: Problem using input in Dictionary.. Help - by ThomasL - Aug-25-2019, 08:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using input command akbarza 4 1,157 Oct-19-2023, 03:27 PM
Last Post: popejose
  problem in entering address of a file in input akbarza 0 661 Oct-18-2023, 08:16 AM
Last Post: akbarza
  Problem with input after function luilong 10 4,121 Dec-04-2021, 12:16 AM
Last Post: luilong
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,643 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  single input infinite output problem Chase91 2 1,962 Sep-23-2020, 10:01 PM
Last Post: Chase91
  How do you replace a dictionary key with a new input? thewetmosquito 4 3,343 Aug-23-2020, 03:48 AM
Last Post: perfringo
  Problem with the input marios 4 2,077 May-03-2020, 01:01 PM
Last Post: marios
  User input & Dictionary tfernandes 5 3,664 Apr-03-2020, 07:12 PM
Last Post: tfernandes
  problem coverting string data file to dictionary AKNL 22 6,475 Mar-10-2020, 01:27 PM
Last Post: AKNL
  Get a value from a dictionary through input Anony 3 2,296 Jan-26-2020, 06:18 PM
Last Post: buran

Forum Jump:

User Panel Messages

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