Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing a program
#1
Have been trying to learn about dictionaries in Python 3 at Understanding Dictionaries in Python 3

# Define original dictionary
usernames = {'Sammy': 'sammy-shark', 'Jamie': 'mantisshrimp54'}

# Set up while loop to iterate
while True:

    # Request user to enter a usernames
    print('Enter a name:')

    # Assign to name variable
    name = input()

    # Check whether name is in the dictionary and print feedback
    if name in usernames:
        print(usernames[name] + ' is the name of ' + name)

    # If the name is not in the dictionary...
    else:

        #provide feedback
        print('I don\'t have ' + name + '\'s username, what is it?')

        # Take in a new username for the associated username
        username = input()

        # Assign username value to name key
        usernames[name] = usernames

        # Print feedback that the data was updated
        print('Data updated.')
But when i try to close the program using Ctrl + C i get the following error:
^CTraceback (most recent call last)
   File "/home/oldDog/usernames.py", line 13, in <module>
     name = input()
KeyboardInterrupt
Could someone help me please
Reply


Messages In This Thread
Closing a program - by oldDog - Jul-28-2018, 12:39 PM
RE: Closing a program - by gontajones - Jul-28-2018, 12:54 PM
RE: Closing a program - by oldDog - Jul-28-2018, 01:22 PM
RE: Closing a program - by snippsat - Jul-28-2018, 02:52 PM
RE: Closing a program - by oldDog - Jul-29-2018, 10:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Closing a program using a G10 button MBDins 2 1,949 May-23-2021, 05:49 PM
Last Post: MBDins
  Try-except in while loop: error with closing program Lupin_III 7 3,034 Jul-03-2020, 10:57 AM
Last Post: Lupin_III

Forum Jump:

User Panel Messages

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