简体   繁体   English

使用 python 求解满足条件的值

[英]Using python to solve for value that meets a condition

new true value that meets the condition = v满足条件的新真值 = v

previous true value = vprev前一个真值 = vprev

I am trying to look for av so that hash of str(((power(v,2))+(power(vprev, 3))) begins with ee我正在尝试寻找 av 以便 str(((power(v,2))+(power(vprev, 3))) 的 hash 以 ee 开头

I tried this我试过这个

import hashlib
values_list = []# a list where v and prev will be
solved = False
v = 1 # to start looping from 1

while not solved:
    for index, v in enumerate(values_list):
        vprev = values_list[(index - 1)]
    results = str(v**2 + vprev**3)
    results_encoded = results.encode()
    results_hashed = hashlib.sha256(results_encoded).hexdigest()
    if results[0:2] == "ee":
        solved = True
        values_list.append(v)
    else: v += 1

print(values_list)

I'm expecting a list with the first true value but I have failed我期待一个具有第一个真值的列表,但我失败了

Commenting your own code:评论你自己的代码:

# ...
solved = False
v = 1 # to start looping from 1

while solved:
    # This block is never executed: the `while` condition-check fails since the initial state of `solved` is `False`

print(values_list)

you'll probably want to use while not solved: instead你可能想while not solved:而不是

import hashlib
values_list = []# a list where v and prev will be
solved = False
v = 1 # to start looping from 1

while not solved:
    for index, value in enumerate(values_list):
        vprev = values_list[(index - 1)]
    results = str(v**2 + vprev**3)
    results_encoded = results.encode()
    results_hashed = hashlib.sha256(results_encoded).hexdigest()
    if results[0:2] == "ee":
        values_list.append(v)
        solved = True
    else: v += 1

print(values_list)

While loop is working for "true" statment.虽然循环正在为“真实”声明工作。 So you have to change your statments on code.所以你必须改变你的代码声明。 And If you make the statment false then while loop breaks the loop.并且如果您使语句为假,则 while 循环会中断循环。

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

相关问题 如果记录满足条件,则使用先前记录值的Python偏移列值 - Python offset column value with previous record value if the record meets a condition 如果值满足条件python的快速计数方法 - faster method of counting values if the value meets the condition python Python-v3.6.3:在满足条件的列表中查找一个值,然后根据原始值查找另一个满足不同条件的值 - Python - v3.6.3: Find a value in a list that meets a condition and then find another value that meets a different condition based on original value 使用 python 生成器在项目满足条件后继续循环 - Continue the loop once the item meets a condition using a python generator Python-如果符合条件则关闭文件 - Python - closing a file if it meets a condition 组 dataframe 直到列值满足条件 - Group dataframe with until column value meets the condition 条件满足时更新数据框中的值 - Update value in data frame when condition meets 获取满足条件的最后一个可用值 - Get the last available value that meets a condition Pandas - 使用列计算值时,当列满足条件时将值设置为 0 - Pandas - when calculating a value using a column, set the value to 0 when the column meets a condition Python:如果列中的第n个值满足特定条件,则对整个列执行计算 - Python: Performing calculation on entire column if nth value in the column meets certain condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM