Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to create packed binary data, using struct.pack() in python3.x
It is giving me the below error, but I am unable to understand.
packed1 = struct.pack('>i4', 7, 8)
errorTraceback (most recent call last)
<ipython-input-823-a27a6bc07ff4> in <module>()
----> 1 packed1 = struct.pack('>i4', 7, 8)
error: repeat count given without format specifier
The repeat count should be before the i
struct.pack('>4i', 7, 8, 3, 2)
Also you need 4 parameters not only 2
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
lukaspertl#dhcp-10-241-163-47 Cambridge year 2 % /usr/local/bin/python3 "/Users/
lukaspertl/OneDrive - University of Cambridge/Cambridge year 2/Coding/Task4/Bise
ctionMethod.py"
n:3546/usr/local/bin/python3 "/Users/lukaspertl/OneDrive - University of Cambridge/Cambridge year 2/Coding/Task4/BisectionMethod.py"
Traceback (most recent call last):
File "/Users/lukaspertl/OneDrive - University of Cambridge/Cambridge year 2/Coding/Task4/BisectionMethod.py", line 5, in <module>
n = int(input("n:"))
^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '3546/usr/local/bin/python3 "/Users/lukaspertl/OneDrive - University of Cambridge/Cambridge year 2/Coding/Task4/BisectionMethod.py"'
I tried to convert to float first but no better results.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
def ShowData(data = (x)):
for r in data:
print (“{:}, {:.2f}”.format(x, x))
keep getting this error:
File "<ipython-input-10-9963f96f39ca>", line 8
print (“{:}, {:.2f}”.format(x, x))
^
SyntaxError: invalid character in identifier
Replace the “ charachter with this " ?
# data is a list of lists
def ShowData(data = (x)):
for r in data:
print ("{:}, {:.2f}".format(x, x))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What is the correct syntax for using Sum() function in python for lists?
Say we have a list called list_1. When I tried these two syntax I get the same result:
total_1 = Sum(list_1)
total_2 = list_1.Sum()
What is the best syntax for that?
To sum a list of integers or floats, the correct method is:
list_1 = [1, 2, 3]
total = sum(list_1)
print(total)
which results in the output:
6
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I run the following in Python 2.7
import numpy
a = numpy.ndarray(shape=(2,2), dtype=float, order='F')
print numpy.mean(a)
numpy.savetext('foo.txt', a)
and get this result
[me#foo bar]$ python f.py
8.79658981512e-317
Traceback (most recent call last):
File "f.py", line 4, in <module>
numpy.savetext('foo.txt', a)
AttributeError: 'module' object has no attribute 'savetext'
What's wrong?
It's numpy.savetxt, without the e.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am new to this and am receiving an error that says print (line 5) is an invalid syntax
from random import randint
r=randint
while True:
s=int(input('How many sides would you like on your die')
print (r(1,s))
The problem is not actually on line 5, but on line 4. You have two ( brackets but only one ). In search of the final ) the Python interpreter checks the following line, and only at that point does it raise the error.
s=int(input('How many sides would you like on your die')
^
There is a closing parenthesis missing.