此任务所需的两个文件的路径已存储在变量 file_path_1 和 file_path_2 中
对file_path_1和file_path_2调用上一个任务中编写的函数readfile(),并将它们的消息语句分别存储在变量message_1和message_2中。
打印 message_1 和 message_2 以查看它们包含的内容。
编写一个函数fuse_msg():
将message_a和message_b作为参数
实现 message_a 除以 message_b 的整数(下限)除法(在应用下限除法之前不要忘记将消息设置为 int)并将商存储在名为 quotient 的变量中
以字符串格式返回商。
[Note you can convert any variable 'a' to string using str(a)] read_file() is already defined in another
message_1 = read_file(file_path_1)
message_2 = read_file(file_path_2)
print(message_1)
print(message_2)
def fuse_msg(message_a , message_b) :
quotient = int(message_b // message_a)
return str(quotient)
secret_msg_1 = fuse_msg(message_1,message_2)
最佳答案
除法之前需要将message_b和message_a转换为int或float
message_1 = read_file(file_path_1)
message_2 = read_file(file_path_2)
print(message_1)
print(message_2)
def fuse_msg(message_a , message_b) :
quotient = int(message_b) // int(message_a)
return str(quotient)
secret_msg_1 = fuse_msg(message_1,message_2)
关于python - 文件处理中的 int 函数和 str() 函数。我不知道哪里出了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57477253/