You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 3, 2026. It is now read-only.
user_input=input('Please enter your transaction value: ')
28
+
add__line()
29
+
returnuser_input
30
+
31
+
defreturn_all_blocks():
32
+
print('---Outputting all blocks---')
33
+
# A for loop is used to iterate over a list, executing the same block of code for each item in the list
34
+
# In this case, the loop will print each block of the blockchain in a different line
35
+
forblockinmy_blockchain:
36
+
print('Outputting block: '+str(block))
37
+
add__line()
38
+
39
+
defverify_chain_by_index():
40
+
""" The same function as verify_chain but using the index of the blocks instead of the block itself """
41
+
is_valid_chain=True
42
+
# There is no index number in a for loop for python, but it can be used through the range() function
43
+
forblock_indexinrange(len(my_blockchain)):
44
+
ifblock_index==0:
45
+
# In case you are in the first index, there is no need to check anything, so just continue to the next iteration (continue will skip the iteration and will continue with the next one)
46
+
block_index+=1
47
+
continue
48
+
# The idea in this if is that che the first element of the current block (block[0]) should be equal to the entire previous block (my_blockchain[block_index - 1])
""" The function helps to verify the integrity of the blockchain by checking if each block's previous hash matches the hash of the previous block. """
58
+
block_index=0
59
+
is_valid_chain=True
60
+
61
+
forblockinmy_blockchain:
62
+
ifblock_index==0:
63
+
# In case you are in the first index, there is no need to check anything, so just continue to the next iteration (continue will skip the iteration and will continue with the next one)
64
+
block_index+=1
65
+
continue
66
+
# The idea in this if is that che the first element of the current block (block[0]) should be equal to the entire previous block (my_blockchain[block_index - 1])
67
+
elifblock[0] !=my_blockchain[block_index-1]:
68
+
is_valid_chain=False
69
+
break
70
+
71
+
block_index+=1
72
+
returnis_valid_chain
73
+
74
+
defadd__line():
75
+
print('---------------------')
76
+
77
+
# A while loop is used to execute a block of code as long as a certain condition is true
78
+
# In this case, the true related to the waiting_for_input variable
79
+
whilewaiting_for_input:
80
+
add__line()
81
+
print('Please choose an option:')
82
+
print('1: Add a new block to the blockchain')
83
+
print('2: Output all blockchain blocks')
84
+
print('h: Manipulate blockchain')
85
+
print('q: Quit')
86
+
add__line()
87
+
88
+
user_choice=get_user_input()
89
+
90
+
# The if else conditional statement gives you the option to execute different blocks of code based on a condition
0 commit comments