我有一个包含元素的数组[50, 20, 20, 5, 2]
,称为coins_used
.
我需要计数然后输出硬币在数组中出现的次数。使用coin_used x frequency
.
无论如何,我可以计算元素在数组中出现的次数,输出需要完全像这样:
50x1,20x2,5x1,2x1
最简单的方法是如何做到这一点?
即使语法似乎都正确我仍然抛出输出错误,为什么它会在输出上抛出这个?(请忽略我的不良缩进).
import zipfile
myZip = zipfile.ZipFile("/mydile.zip")
count = 0
for x in range(0,1005310):
password = count
count += 1
try:
myZip.extractall(pwd = password)
print(password)
except Exception as e:
print(e)
print "Sorry, password not found."
Run Code Online (Sandbox Code Playgroud) 试图在控制台应用程序中完成一个库存系统,因此我被困在这一部分,以确保用户不能有一个重复的8位长的ID号,我的问题如下.
基本上我不确定为什么这个代码不起作用,我可能在这里错过了一段非常明显的代码,帮助将被赞赏,已经尝试改变已经存在的值,所以有可能忽略了一个值.
static int checkIDNumber(int ID)
{
// Check the number passed in & then loop through all the lines...
// If number is taken then output error, because id exists already
// Else allow the value to be used in the stock system.
int IDNumber = ID;
using (StreamReader sr = new StreamReader("Stockfile.txt"))
{
string lineValues;
while (sr.EndOfStream == false)
{
lineValues = sr.ReadLine();
if (lineValues.Contains(IDNumber.ToString()))
{
Console.WriteLine("Id number is currently already taken.");
}
else
{
return IDNumber;
} …
Run Code Online (Sandbox Code Playgroud)