-4
In one of the examples, on page 92 of the book "Introduction to Programming with Python: Algorithms and Programming Logic for Beginners - Nilo Ney Coutinho" he gives us the code below, but I am doubtful why he replaces the variable 'delete' with 'value', could not simply use the variable "value". I’m starting now in programming on my own and would like to understand why.
valor = int(input("Digite o valor a pagar:"))
cédulas = 0
atual = 50
apagar = valor
while True:
if atual <= apagar:
apagar -= atual
cédulas +=1
else:
print(f"{cédulas} cédulas de R$ {atual}")
if apagar == 0:
break
if atual == 50:
atual = 20
elif atual == 20:
atual = 10
elif atual == 10:
atual = 5
elif atual == 5:
atual = 1
cédulas = 0
There is no need to use the variable
apagar
. I understand that the creator of this code used two variables because it is changing the value ofapagar
then, which means that if he needed to use again the original value entered by the user, he would still have this value saved in the variablevalor
. This is not the case, but it can still be considered a good practice.– Andre