Reputation: 9
Don't understand why I'm getting tuple error out of range. Please Help
contactname_1 = input('Enter the 1st contact name:')
contactnum_1 = input('Enter the 1st contact phone number: ')
contactmail_1 = input('Enter the 1st contact email: ')
contactname_2 = input('Enter the 2nd contact name: ')
contactnum_2 = input('Enter the 2nd contact phone number: ')
contactmail_2 = input('Enter the 2nd contact email: ')
Display_align = input('Enter display alignment left/right/center (L/R/C)?')
if (Display_align == 'L'):
print('{0:<30} {1:<30} {2:<30}'.format('Name' + 'Phone' + 'Email'))
print('{0:<30} {1:<30} {2:<30}'.format(contactname_1, contactnum_1, contactmail_1))
print('{0:<30} {1:<30} {2:<30}'.format(contactname_2, contactnum_2, contactmail_2))
Upvotes: 0
Views: 39
Reputation: 533
In the first print statement, you need a tuple of three in the format method. Adding 'Name', 'Phone' and 'Email' gives a single string. Replace
print('{0:<30} {1:<30} {2:<30}'.format('Name' + 'Phone' + 'Email'))
with
print('{0:<30} {1:<30} {2:<30}'.format('Name', 'Phone','Email'))
Upvotes: 0
Reputation: 93
You concatenate strings when you pass them as args to format.
Here is the corrected version:
print('{0:<30} {1:<30} {2:<30}'.format('Name', 'Phone', 'Email'))
Upvotes: 1