错误与字典键和python中的值转换(erros with dictionary keys and values conversion in python)
我在python中为埃及部门编写代码。 什么是埃及师例如,17除以3。
Powers of two column divisor doubling column 2^0 = 1 3 2^1 = 2 6 2^2 = 4 12 2^3 = 8 24 24>17 so we can stop.
看看3,6和12的组合,我们看到12 + 3 = 15是我们在没有超过17的情况下看起来最接近的。
现在我得到了上面的输出,但我无法得到商,因为我使用字典,它给了我一个错误。
import sys astring = raw_input("Enter the A integer: ") #accepting input a = int(astring) #dividend bstring = raw_input("Enter the B integer: ") # accepting input b = int(bstring) #divisor Egyptian_Division_dict = {} # initiating dictionary i =0 # setting counter for 2^i x =0 z =0 #k = 0 #m = 0 list_of_divisor = [] list_of_two = [] while i< a: k = 2**i m = k*b if m < a: list_of_divisor.append (k) list_of_two.append(m) i += 1 for i in range(len(list_of_divisor)): Egyptian_Division_dict[list_of_divisor[i]] = list_of_two[i] list_of_divisor = sorted(list_of_divisor, reverse=True) list_of_two = sorted(list_of_two, reverse=True) print "printing dictionary" for keys,values in sorted (Egyptian_Division_dict.items(),reverse = True): print (keys), (values) #if z == a: # z=+value #print z rough = 0 quetient = 0 for keys in sorted (Egyptian_Division_dict.items(),reverse = True): #Egyptian_Division_dict[keys] = str([keys]) #Egyptian_Division_dict[values] = str([values]) w = keys z = values if rough + z <a: rough = rough+z quetient = quetient + w else : print quetient
错误:
Enter the A integer: 44 Enter the B integer: 4 printing dictionary 8 32 4 16 2 8 1 4 Traceback (most recent call last): File "main.py", line 39, in <module> quetient = quetient + w TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
如何删除此错误?
I am writing a code for Egyptian division in python. what is Egyptian division For example, 17 divided by 3.
Powers of two column divisor doubling column 2^0 = 1 3 2^1 = 2 6 2^2 = 4 12 2^3 = 8 24 24>17 so we can stop.
Looking at the combinations of 3, 6, and 12 we see that 12 + 3 = 15 is the closest we can seem to get without going over 17.
Now I got the above output but i couldn't get the quotient as i am using dictionary and it gives me an error.
import sys astring = raw_input("Enter the A integer: ") #accepting input a = int(astring) #dividend bstring = raw_input("Enter the B integer: ") # accepting input b = int(bstring) #divisor Egyptian_Division_dict = {} # initiating dictionary i =0 # setting counter for 2^i x =0 z =0 #k = 0 #m = 0 list_of_divisor = [] list_of_two = [] while i< a: k = 2**i m = k*b if m < a: list_of_divisor.append (k) list_of_two.append(m) i += 1 for i in range(len(list_of_divisor)): Egyptian_Division_dict[list_of_divisor[i]] = list_of_two[i] list_of_divisor = sorted(list_of_divisor, reverse=True) list_of_two = sorted(list_of_two, reverse=True) print "printing dictionary" for keys,values in sorted (Egyptian_Division_dict.items(),reverse = True): print (keys), (values) #if z == a: # z=+value #print z rough = 0 quetient = 0 for keys in sorted (Egyptian_Division_dict.items(),reverse = True): #Egyptian_Division_dict[keys] = str([keys]) #Egyptian_Division_dict[values] = str([values]) w = keys z = values if rough + z <a: rough = rough+z quetient = quetient + w else : print quetient
error:
Enter the A integer: 44 Enter the B integer: 4 printing dictionary 8 32 4 16 2 8 1 4 Traceback (most recent call last): File "main.py", line 39, in <module> quetient = quetient + w TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
How can I remove this error?
原文:https://stackoverflow.com/questions/35749963
最满意答案
来自Xen wiki:
Error: Device 0 (vif) could not be connected. Hotplug scripts not working.
此问题通常是由于没有在dom0内核中加载“xen-netback”驱动程序引起的。
默认情况下,hotplug脚本位于/ etc / xen / scripts中,并标有前缀vif- *。 这些脚本会记录到/var/log/xen/xen-hotplug.log,可以在那里找到更详细的信息。
From the Xen wiki:
Error: Device 0 (vif) could not be connected. Hotplug scripts not working.
This problem is often caused by not having "xen-netback" driver loaded in dom0 kernel.
The hotplug scripts are located in /etc/xen/scripts by default, and are labeled with the prefix vif-*. Those scripts log to /var/log/xen/xen-hotplug.log, and more detailed information can be found there.
相关问答
更多-
如何解决在Android ADB主机设备中未经授权的ADB设备?(How to solve ADB device unauthorized in Android ADB host device?)[2022-05-07]
从客户端手机获取公钥(adb主机) cat /data/.android/adbkey.pub 将上面的公钥复制到目标手机的/data/misc/adb/adb_keys位置。 (您可能需要先停止adb守护进程并stop adbd ) cat / data / misc / adb / adb_keys 验证两个cat输出匹配。 尝试在目标start adbd上重新启动adb守护程序或重新启动它们。 如果在上述步骤中读取或写入ADB KEYS时遇到问题,请尝试使用临时路径(例如: /data/local/t ... -
管道输出以find和分析errorlevel: adb devices -l | find "device product:" >nul if errorlevel 1 ( echo No connected devices ) else ( echo Found! .............. ) Pipe the output to find and analyse the errorlevel: adb devices -l | find "device product:" ...
-
在使用statsmodels时确认,一定要注意添加常量(在这种情况下这是必需的) 参考MATLAB: https : //www.mathworks.com/help/econ/examples/time-series-regression-ii-collinearity-and-estimator-variance.html Confirmed when using statsmodels, always be mindful of adding constant (which is necessary ...
-
构建到apk后无效的密钥哈希以及如何解决这个问题的许多设备?(Invalid key hash after build to apk and how to solve this for many device?)[2023-09-17]
我们必须在Facebook开发人员中添加三个关键哈希值。 1.使用android应用程序中的包管理器。 try { PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { ... -
显然, vif无法处理一个mlm对象(多个DV)。 运行单独的模型并检查它们。 Apparently, vif can't deal with an mlm object (multiple DVs). Run separate models and check them.
-
如何解决“设备0(vif)无法连接。(How to solve “Device 0 (vif) could not be connected. Hotplug scripts not working.”?)[2022-08-15]
来自Xen wiki: Error: Device 0 (vif) could not be connected. Hotplug scripts not working. 此问题通常是由于没有在dom0内核中加载“xen-netback”驱动程序引起的。 默认情况下,hotplug脚本位于/ etc / xen / scripts中,并标有前缀vif- *。 这些脚本会记录到/var/log/xen/xen-hotplug.log,可以在那里找到更详细的信息。 http://wiki.xen.org/w ... -
看起来您已将调试器附加到目标。 (1)忽略WinDbg状态消息。 查看您是否已连接到目标的最佳方法是尝试一些命令。 (2)当我调试虚拟机时,我正在使用的串口也会丢失,但看起来你想出来了(干得好)。 要发出命令,您需要进入内核。 单击“Debug-> Break”并尝试以下命令: .reload !ustr srv!SrvComputerName 这应该为您提供目标系统计算机名称。 如果您想了解有关内核调试的更多信息,我会在YouTube上查看TheSourceLens 。 至于文学,我不能推荐任何书籍, ...
-
发生这种情况是由于与设备通信的低级别USB问题导致设备进入无法恢复状态。 一旦设备进入此状态并且重置不起作用,您必须通过拔下USB插头重新插入USB设备并重新插入USB设备。 通过告诉USB驱动程序使用USB 1.0速度,您可以更少发生这种情况。 但是,这样做会降低网络速度,使一些USB 2.0键盘不再工作。 是否应该这样做取决于您的使用案例。 有关更改USB速度的说明,请访问: http : //www.raspberrypi.org/forums/viewtopic.php?t = 34120 This ...
-
VIF包中的vif函数不估计方差膨胀因子(VIF)。 “它选择线性模型的变量”和“返回用于构建线性模型的变量子集。”; 请看这里的描述。 你想要的是car包装的vif功能。 install.packages("car") library(car) vif(model2) # This should do it 编辑:我不会在统计方面做出具体评论,但似乎你有一个完美的契合,一些非常不寻常的东西,暗示你的数据存在一些问题。 The vif function from the VIF package does ...