简体   繁体   English

如何拆分一组int数据来确定最后两位数字的值?

[英]How to split a set of int data to determine the value of the last two digits?

I have a csv file that one of the columns called timestamp (in hour and minutes; eg 1041 means 10:41).我有一个csv文件,其中一列称为时间戳(以小时和分钟为单位;例如 1041 表示 10:41)。

I want to make sure that the imported data is in the correct format.我想确保导入的数据格式正确。 For example, the program should issue a warning if the data is 1061.例如,如果数据是 1061,程序应该发出警告。

My current idea is to detect the last two digits of the data.我目前的想法是检测数据的最后两位数字。 If it is greater than 60, an alarm is triggered.如果大于 60,则触发警报。 What should I do?我该怎么办?

Well checking last two digits means finding the remainder after dividing by 100 (modulo operator):检查最后两位数字意味着找到除以 100 后的余数(模运算符):

num = 1061
min = num % 100 # 61

if min > 60:
  print("Error in minutes by {} minute(s)".format(min % 60))
else:
  print("Success")

Without your code there is not much more I can say to help.没有您的代码,我无法提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM