in Education by
The code works fine but the only problem I encountered an error is: bad operand type for unary +: 'str'. This is my code: express_file = {'TPLEX':'Pangasinan', 'SLEX':'Subic', 'Cavitex':'Bacoor,Cavite','MCX':'Muntinlupa','Star Tollway':'Laguna'} for x,y in express_file.items(): print(x,'runs through',+y+ '.') print('The following Expressway are included in this data set:') for x in express_file.keys(): print(x) print('\nThe following Provinces are included in this data set:') for x in express_file.values(): print(x) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 1 express_file = {'TPLEX':'Pangasinan', 'SLEX':'Subic', 'Cavitex':'Bacoor,Cavite','MCX':'Muntinlupa','Star Tollway':'Laguna'} 2 for x,y in express_file.items(): ----> 3 print(x,'runs through',+y+ '.') 4 print('The following Expressway are included in this data set:') 5 for x in express_file.keys(): TypeError: bad operand type for unary +: 'str' Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Use the print with an f-string # replace print(x,'runs through',+y+ '.') # with print(f'{x} runs through {y}.' # or with print(x,'runs through ' +y+ '.') # note the added space after through and the removal of the , Updated script express_file = {'TPLEX':'Pangasinan', 'SLEX':'Subic', 'Cavitex':'Bacoor,Cavite','MCX':'Muntinlupa','Star Tollway':'Laguna'} for x,y in express_file.items(): print(f'{x} runs through {y}.') print('The following Expressway are included in this data set:') for x in express_file.keys(): print(x) print('\nThe following Provinces are included in this data set:') for x in express_file.values(): print(x) [out]: TPLEX runs through Pangasinan. SLEX runs through Subic. Cavitex runs through Bacoor,Cavite. MCX runs through Muntinlupa. Star Tollway runs through Laguna. The following Expressway is included in this data set: TPLEX SLEX Cavitex MCX Star Tollway The following Provinces are included in this data set: Pangasinan Subic Bacoor,Cavite Muntinlupa Laguna Do check out python for data science course which helps you understand from scratch.

Related questions

0 votes
    please see my code below, example_list = [ ['a','b','c'], ['f','g','h'], ['i','j','k'], ] my_string = ''' ' ... g','h'), ('i','j','k'); Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am new to python, I have this code: # columns are [0]title [1]year [2]rating [3]length(min) [4]genre ... make that int into a list? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Here's the code: ''' file_path = (r'C:\Users\Luka\Desktop\Pyhton exercises\pi_digits.txt') with open( ... file_object: print(line) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have a set of oil wells compiled in the panda's data frame. It looks like this: wells = pd.DataFrame({'date ... -01-01 FIELDZ 10.8 Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    This is my function: def sub(number): tmp = [] tmp.append(number) while len(str(number)) > 1: tmp.append( ... do this in the python? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Hi, I am a relatively new programmer and my teacher gave us this problem to fix. Thing is, I have no idea ... wrong with this problem? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    A few days ago I've started learning pygame. So, now I've got the code which allows me to draw different ... ) py.display.update() Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me where can I learn Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    webbrowser.open('https://api.WhatsApp.com/send?phone=number') I want to send WhatsApp messages to numbers without ... in this link. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how do I start learning Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Do I need coding skills for Data Science using Python? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what should I learn in Python for Data Science? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    I used the pyhton: for m in regex.findall(r"\X", 'ल्लील्ली', regex.UNICODE): for i in m: print(i, i.encode(' ... कृ','प','या','ल्ली' Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I would like to clear the written email and write password grid when a del button is pressed, and then I ... mainloop() EmailPassword() Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
...