Python Forum
Dictionaries in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionaries in Python
#1
Hello guys , I was just trying to write some codes to run Dictionary exercises then I found myself stuck in trouble writing some parts of code .
# Add two dictionary and assign it to dict3 Display the dict3
dictFirst = {'maths': '24' , 'science': '58' , 'history':'76'}
dictSecond = {'sports': '16' , 'music': '83'}
dictResult = {**dictFirst , **dictSecond}
print(dictResult)

# Clear the dictionary dict2 Display the dict2
dictSecond.clear()
print(dictSecond)

# Delete the dictionary dict1

''' 
Get input from the user and print the score in that subject 

  if not available print proper message.

  (user input can be of any case.) 
'''
In line 11 up to 18 , I can't get any heads or tails around what am I supposed to do with it .
I'm very thankful If you can help me doing this . Thanls
Reply
#2
You get user input using the input function (answer = input('question? ')), you allow for any case by lower casing it (answer.lower()), and you access dictionary items with brackets (dictResult['maths']).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with Python dictionaries kam_uk 5 2,452 Dec-22-2020, 11:32 PM
Last Post: jefsummers
  Newbie to Python - Problem in accessing Dictionaries and List sambill 1 3,030 Aug-17-2017, 07:38 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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