简体   繁体   中英

confused about this error in printing array in python?

Consider the following code; I want to print the array Ptimes 3 spaces from the beginning of console screen. I have tried

print "   %s" %(Ptimes) 

when I use this form nothing printed it says that there is error "all arguements covered due too string formatting.

the original worked code is:

PN = input("   Enter each process time following by its arrival time separated by comma: ")

Ptimes = PN[::2]  
Atimes = PN[1::2]
print    Ptimes
print    Atimes 

Ptimes is a tuple, and Python wants to find placeholders for each *element in Ptimes . Wrap it in a tuple (add a comma) instead:

print "   %s" % (Ptimes,)

Demo:

>>> Ptimes = ('foo', 'bar')
>>> print "   %s" % (Ptimes)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> print "   %s" % (Ptimes,)
   ('foo', 'bar')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM