我正在让用户输入要打开的文件,其中包含数字.我希望输出是文件中的元素数.我放..
file=open(input("Please enter the name of the file you wish to open:" ))#, "r")
A= file.readline()
print (A)
n=len(A)
print (n)
Run Code Online (Sandbox Code Playgroud)
我对此很新.我正在测试它的文件有9个数字(其中2个为负数).长度达到21.如何更改此项以获取元素数量?
我正在努力解决这个问题.基本上,这个function void check(char *tel, char *c)
数组的第一个值必须是数字2
,而其他数字必须是数字之间的数字0 and 9
.如果满足条件,将打印V
,否则将打印F
.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
void check(char *tel, char *c){
int i;
if(*tel!=2) printf("Error\n");
*c='F';
return; //I guess this return is wrong
if(*tel==2)
for(i=0;tel[i]<9;i++){
if(isdigit(tel[i]));
else{
printf("Error!\n");
*c='F';
break;
return;} //this one might be in bad use too
}
else
*c='V'; //having troubles here.. i'm not seeing a way to fix this
}
int main(){
char number[9]={2,3,4,5,6,7,4,5,3};
char car;
check(number,&car);
printf("%c \n", car); …
Run Code Online (Sandbox Code Playgroud) 我如何让它工作?
n = 1234
f = open("file", "r")
while True:
x=f.readline()
print "*********************"
print n%(long(x))
if n%(long(x))==0:
print x
else:
print "..."
Run Code Online (Sandbox Code Playgroud)
我是python中的菜鸟,我收到一个我不明白的错误.我究竟做错了什么?
ValueError: invalid literal for long() with base 10: ''
Run Code Online (Sandbox Code Playgroud) 编译器告诉我我不能在构造函数中进行赋值.我在另一个类中有非常相似的代码,它编译得很好.
class Dependency {
public:
Dependency(std::function<void ()> const & func);
private:
std::function<void ()> const call_back;
};
Dependency::Dependency(std::function<void ()> const & func){
call_back = func;
}
Run Code Online (Sandbox Code Playgroud) 我需要这样的东西
public enum SolutionType {
RMS,
CPA,
BUSINESS DRIVERS,
NA
}
Run Code Online (Sandbox Code Playgroud)
商业驱动力是空间的价值所在
我可能在矩阵中发现了一个故障。一位客户报告了一个错误:他们通过后端设置了产品价格4.99
,并说保存为4.98。
我怀疑他们输入了错误的值,所以我自己测试了它,确实该值出现了,而4.98
不是4.99
。所有其他产品价格似乎不受影响。一堆 0.99s、1.99s 和 19.99s。我认为我们最近可能引入了这个错误,因为这是客户第一次也是唯一一次报告看到这样的问题。
为了给您提供更多背景信息,它是一个 React UI,它使用 apollo graphql 将数据推送到 Rust (actix) 后端。然后,后端将需要保存的任何内容保存在数据库中,并且产品价格通过其 API 发送到 stripe。4.98 是条纹的。Stripe API 接受价格的方式是单位金额,即美分,而不是美元。所以4.99
应该以条纹着陆499
。根据我们后端发送的他们的仪表板498
。啥?!
几分钟后
我无法缩小代码中任何明显错误的范围。graphql 突变将其作为浮点值发送,它再次4.99
保存在我们的数据库中,但价格最终以条带形式出现。FLOAT(4,2)
4.99
4.98
我们为 stripe API 准备值的方式是:
let unit_amount = (product_price_row.price * 100f32) as i64;
Run Code Online (Sandbox Code Playgroud)
product_price_row
SeaORM 行所在的price
位置是4.99
。
在这种情况unit_amount
下最终为498
.
似乎没有其他值会出现这样的故障。
我意识到这是一些奇怪的浮点错误簇,但它引起了我的注意。我写了一个小的 Rust 沙箱来说明发生了什么。要亲自测试它,请检查此 存储库。
基本上可以归结为以下几点:
let i = 4.99; // any other .99 number …
Run Code Online (Sandbox Code Playgroud) 我需要一个可变向量来包含对结构内部其他对象的引用。Rust 抱怨我无法在结构内部使用“let”,但我仍然没有找到在线 Rust 书中列出的使编译器满意的方法。
元对象协议结构需要有一个私有容器来存储其操作所需的其他对象的地址。Rust 有办法做到这一点吗?
pub struct MetaObjectProtocol {
// Metaobject Registry
// Container holding references to all existing Metaobjects
let mut mop_registry = Vec<MetaObject>;
}
Run Code Online (Sandbox Code Playgroud) 是否有可能自动生成这样的东西?我只想要特定成员一次并生成三个类(它们相似,但......)
class recipe{
public:
int timeToPrepare;
std::string name;
}
class recipeQuery{
public:
baseQuery<int> timeToPrepare;
baseQuery<std::string> name;
}
class recipeScheme{
public:
schemeItem<int> timeToPrepare;
schemeItem<std::string> name;
}
Run Code Online (Sandbox Code Playgroud) 我在这里写了这段代码.它应该打印出iteNum.length
由用户输入确定的(数组),但它只进行一次迭代然后停止.我无法弄清楚为什么.
for (int i = 0; i < iteNum.length; i++) {
System.out.print("Num:" + (i+1) + " ");
for (i = 0; i < cMiles.length; i++) {
System.out.print(" (sc" + (i+1) + ":)" + cRandom[i] + " (tsc" + (i+1) + ":)" + df.format(cTimes[i]) + " ");
}
for (i = 0; i < fMiles.length; i++){
System.out.print(" (sf"+ (i+1) + ":)" + df.format(fRandom[i]) + " (tsf" + (i+1) + ":)" + df.format(fTimes[i])+ " " );
}
System.out.print("(cT:)" + df.format(cSum) …
Run Code Online (Sandbox Code Playgroud)