Code:
labels = ['Python', 'Java', 'JavaScript', 'C#', 'PHP']
data_set = [29.9, 19.1, 8.2, 7.3, 6.2]
equ_1 = str("=" * (int(data[0])))
equ_2 = str("=" * (int(data[1])))
equ_3 = str("=" * (int(data[2])))
equ_4 = str("=" * (int(data[3])))
max_num = int(max(data))
print("-" * (11 + max_num))
print(F'{labels[0]:9.8s}: {equ_1} \n{labels[1]:9.8s}: {equ_2} \n{labels[2]:9.8s}: {equ_3} \n{labels[3]:9.8s}: {equ_4}')
print("-" * (11 + max_num))
Error:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
TypeError: 'float' object is not callable
Why can I not recall the max of my list data_set ?
I tried print max(data_set) thinking it would print the maximum value in data_set but it is telling me I cannot.
Related
I got an error from this code:
def func(**num):
x = num[a] + num[b] + num[c]
print(x)
func(a=2, b=3, c=4)
The error is this:
Traceback (most recent call last):
File "(erased)", line 4, in <module>
func(a=2, b=3, c=4)
File "(erased)", line 2, in func
x = num[a] + num[b] + num[c]
NameError: name 'a' is not defined
Please explain it why a, b, and c in num[] requires to be put between ''?
I use the Python3.6 and I've been confused about this question for a long time..so here is my code.
def fo(x,y):
z=np.sin(x)+0.05*x**2+np.cos(y)+0.05*y**2
if output == True:
print("%8.4f %8.4f %8.4f" % (x,y,z))
return z
import scipy.optimize as sop
sop.brute(fo,(-10,10.1,5),(-10,10.1,5),finish = None)
Here is the error I get:
Traceback (most recent call last):
File "<ipython-input-12-c7886e35ff4b>", line 1, in <module>
sop.brute(fo,(-10,10.1,5),(-10,10.1,5),finish = None)
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 2811, in brute
if len(lrange[k]) < 3:
TypeError: object of type 'int' has no len()
here's another try:
r1=slice(-10,10.1,5)
r2=slice(-10,10.1,5)
sop.brute(fo,r1,r2,finish = None)
and the error:
Traceback (most recent call last):
File "<ipython-input-48-230c07265998>", line 1, in <module>
sop.brute(fo,r1,r2,finish = None)
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 2804, in brute
N = len(ranges)
TypeError: object of type 'slice' has no len()
sop.brute(fo,(r1,r2),finish = None)
TypeError: fo() missing 1 required positional argument: 'y'
I'm new to here and sorry if I ask a stupid question but I cant' work it out T.T thx a lot
def fo(p):
x, y = p
z = np.sin(x)+0.05*x**2+np.sin(y)+0.05*y**2
if output == True:
print('%8.4f %8.4f %8.4f' % (x,y,z))
return z
unpack tuple like in the code
Here is my code:
from multiprocessing import Pool
user_list = [1, 2, 3, 4, 5]
def gen_pair():
for u1 in reversed(user_list):
for u2 in reversed(list(range(1, u1))):
yield (u1, u2)
def cal_sim(u_pair):
u1, u2 = u_pair
sim = sim_f(df[u1], df[u2])
return sim
pool = Pool(processes=6)
vals = pool.map(cal_sim, gen_pair())
df2record = pd.DataFrame(columns=['u1', 'u2', 'js'])
for v in vals:
print (v)
pool.terminate()
But when I run the code, I got such an error: TypeError: unsupported operand type(s) for +: 'set' and 'set'. The full TraceBack is as below:
Traceback (most recent call last):
File "b.py", line 57, in <module>
main()
File "b.py", line 47, in main
vals = pool.map(cal_sim, gen_pair())
File "yobichi/python/2.7.10_2/lib/python2.7/multiprocessing/pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "yobichi/python/2.7.10_2/lib/python2.7/multiprocessing/pool.py", line 567, in get
raise self._value
TypeError: unsupported operand type(s) for +: 'set' and 'set'
Could you please tell me what is the reason and how can I deal with it appropriately?
You have an infinite recursion here:
def cal_sim(u_pair):
u1, u2 = u_pair
sim = cal_sim(df[u1], df[u2])
return sim
Because cal_sim calls cal_sim without any end condition.
There is also a problem with the parameters, because cal_sim has 1 parameter and you call it with 2 arguments.
This section of my pysolarrobot7.py code is throwing an AttributeError
def tomorrow_heading():
increment_min = 1
incrementeddatetime = 0
tomorrow_corrected = 90
if pysolar.get_altitude(maplat, maplon, datetime.datetime.utcnow()) < 0:
while pysolar.get_altitude(maplat, maplon, (datetime.datetime.utcnow() + datetime.timedelta(minutes=incrementeddatetime))) < 0:
incrementeddatetime = incrementeddatetime + increment_min
sunrise_time=(datetime.datetime.utcnow() + datetime.timedelta(minutes=incrementeddatetime))
tomorrow_heading = pysolar.GetAzimuth(maplat, maplon, sunrise_time)
if tomorrow_heading < 0:
if (tomorrow_heading >= -180):
tomorrow_corrected = ((tomorrow_heading * -1) + 180)
if (tomorrow_heading < -180):
tomorrow_corrected = ((tomorrow_heading * -1) - 180)
if tomorrow_heading >= 0:
The following is the error code
root#Primerpi:/tools# python3 solarrobot7-core.py
Traceback (most recent call last):
File "solarrobot7-core.py", line 237, in <module>
tomorrow_static = tomorrow_heading()
File "solarrobot7-core.py", line 176, in tomorrow_heading
if pysolar.get_altitude(maplat, maplon, datetime.datetime.utcnow()) < 0:
AttributeError: 'module' object has no attribute 'get_altitude'
I've been googling for a while now and can't seem to find the answer. The original code from solarrobot7.py used GetAltitude and Pysolar (PascalCase) and I changed it to get_altitude and pysolar (snake_case).
pysolar don't have an "get_altitude" method:
You want the sub-module "solar" :)
from pysolar import solar
solar.get_altitude #this will work :)
import csv
from geopy import geocoders
import time
g = geocoders.GeocoderDotUS()
spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t', quotechar='|')
f = open("output.txt",'w')
for row in spamReader:
a = ', '.join(row)
#exactly_one = False
time.sleep(1)
place, (lat, lng) = g.geocode(a)
b = str(place) + "," + "[" + str(lat) + "," + str(lng) + "]" + "\n"
print b
f.write(b)
I can't really determine why I am receiving
Traceback (most recent call last):
File "C:\Users\Penguin\workspace\geocode-nojansdatabase\src\yahoo.py", line 17, in
place, (lat, lng) = g.geocode(a)
TypeError: 'NoneType' object is not iterable
I checked to make sure there was a value in a before the geocode(a) call was placed. Perhaps a match was not found? If that is the case the I guess I just have to add in an if not b then statement. Does anyone know more about this?
I am seeing that adding a
a = ', '.join(row)
print(a)
Does yield:
178 Connection Rd Pomona QLD
>>> a, (b, c) = None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
>>> a, (b, c) = ('foo', None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
Your guess is correct. Check before unpacking.