Есть ли способ, которым я могу сократить этот код, чтобы, возможно, использовать цикл, который хранит разные переменные при каждом запуске?Мне нужно, чтобы хранить разные переменные, а не перезаписывать одну и ту же переменную в цикле.На данный момент код очень длинный и заканчивается после пяти итераций, как закодировано, до отображения моих конечных результатов.Любая помощь будет высоко ценится, спасибо!
while True:
opps = float(input("Number of opportunities: "))
sales = float(input("Quantity of of sales: "))
addon = float(input("Addon $ amount: "))
total = float(input("Sales dollar amount: "))
cra = (sales / opps) * 100
addonp = (addon / total) * 100
print("Results:\n" +
"CRA %: " + str(cra) + "%\n" +
"Addon %: " + str(addonp) + "%\n")
ans = 'y'
ans = str(input("Continue? (Y/N)"))
if ans in ['y', 'Y', 'yes', 'Yes', 'YES']:
opps2 = float(input("Number of opportunities: "))
sales2 = float(input("Quantity of of sales: "))
addon2 = float(input("Addon $ amount: "))
total2 = float(input("Sales dollar amount: "))
cra2 = (sales2 / opps2) * 100
addonp2 = (addon2 / total2) * 100
print("Results:\n" +
"CRA %: " + str(cra2) + "%\n" +
"Addon %: " + str(addonp2) + "%\n")
ans = 'y'
ans = str(input("Continue? (Y/N)"))
if ans in ['y', 'Y', 'yes', 'Yes', 'YES']:
opps3 = float(input("Number of opportunities: "))
sales3 = float(input("Quantity of of sales: "))
addon3 = float(input("Addon $ amount: "))
total3 = float(input("Sales dollar amount: "))
cra3 = (sales3 / opps3) * 100
addonp3 = (addon3 / total3) * 100
print("Results:\n" +
"CRA %: " + str(cra3) + "%\n" +
"Addon %: " + str(addonp3) + "%\n")
ans = 'y'
ans = str(input("Continue? (Y/N)"))
if ans in ['y', 'Y', 'yes', 'Yes', 'YES']:
opps4 = float(input("Number of opportunities: "))
sales4 = float(input("Quantity of of sales: "))
addon4 = float(input("Addon $ amount: "))
total4 = float(input("Sales dollar amount: "))
cra4 = (sales4 / opps4) * 100
addonp4 = (addon4 / total4) * 100
print("Results:\n" +
"CRA %: " + str(cra4) + "%\n" +
"Addon %: " + str(addonp4) + "%\n")
ans = 'y'
ans = str(input("Continue? (Y/N)"))
if ans in ['y', 'Y', 'yes', 'Yes', 'YES']:
opps5 = float(input("Number of opportunities: "))
sales5 = float(input("Quantity of of sales: "))
addon5 = float(input("Addon $ amount: "))
total5 = float(input("Sales dollar amount: "))
cra5 = (sales5 / opps5) * 100
addonp5 = (addon5 / total5) * 100
print("Results:\n" +
"CRA %: " + str(cra5) + "%\n" +
"Addon %: " + str(addonp5) + "%\n")
ans = 'y'
ans = str(input("Continue? (Y/N)"))
if ans not in ['y', 'Y', 'yes', 'Yes', 'YES']:
oppst = opps + opps2 + opps3 + opps4 + opps5
salest = sales + sales2 + sales3 + sales4 + sales5
addont = addon + addon2 + addon3 + addon4 + addon5
cratp = (salest / oppst) * 100
tsales = total + total2 + total3 + total4 + total5
addontp = (addont / tsales) * 100
int(oppst)
int(salest)
print("Your totals are: \n" +
"\n" +
"Opportunities: " + str(int(oppst)) + "\n" +
"\n" +
"# of Sales: " + str(int(salest)) + "\n" +
"\n" +
"Addon $ amount: " + "$" + str(addont) + "\n" +
"\n" +
"Addon %: " + str(addontp) + "%\n" +
"\n" +
"CRA %: " + str(cratp) + "%\n" +
"\n" +
"Total Sales: " + "$" + str(tsales)
)
break