I try to make a code that prints two equal random values in a text.
import random
archivo=open('Ejercicio3.txt', 'w')
up=0
insert=int(input('Valor: '))
for i in range(insert):
up+=1
n1=random.randint(10, 100)
n2=random.randint(10, 100)
archivo.write(f'{up}.- {n1} - {n2} = {n1-n2}\n\n')
print(f'{up}.- {n1} - {n2} = {n1-n2}')
archivo.write(f'{n1-n2}\n')#This is the problem, because the code write numbers different random
archivo.close()
What I want is for it to do something similar to this:
import random
archivo=open('Ejercicio1.1.txt', 'w')
up=0
insert=int(input('Valor: '))
for i in range(insert):
up+=1
n1=random.randint(10, 100)
n2=random.randint(10, 100)
archivo.write(f'{n1} - {n2} =''\n\n')
up=0
archivo.write('---------------------------------------------\n')
for i in range(insert):
up+=1
n1=random.randint(10, 100)
n2=random.randint(10, 100)
archivo.write(f'{n1-n2}''\n\n')#Except this part, I want it to be exactly the same as the result of the subtraction above.
archivo.close()
The result i want, is this: Example
Someone can I help me? Thanks very much. Regards
Aucun commentaire:
Enregistrer un commentaire