forked from ChrisKra/JavaScript_QUIZ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomande_fabbisogno2.py
More file actions
184 lines (135 loc) · 5.88 KB
/
domande_fabbisogno2.py
File metadata and controls
184 lines (135 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import random
import os
''' INDEX
- RANDOM PART OF THE EXERCISE genex()
- GENERATE EXERCISE's TEXT printex()
- GENERATE THE HTML CODE WITH EXERCISE show()
'''
tmp = "Calcola l'interesse su 10.000 € al tasso del 7% per 1 anno."
# ======================= RANDOM ELEMENTS OF THE
# TEXT OF THE EXERCISE =====
def genex() -> dict:
''' returns a dictionar with the random data to insert in the text of the exercise'''
s = {
"random_start": random.choice([
"Trova il",
"A quanto ammonta il",
"Calcola il",
"Calcolare il",
"Trovare il",
"Devi trovare il",
"Fai il calcolo del"
])
}
# valore delle merci
merci = s["valore_merci"] = random.randrange(100, 1000, 100)
mese_pag = random.randint(6,12)
acquista = mese_pag - 2
# data del pagament
s["mese_pag"] = random.choice(["giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"])
# data dell'acquisto
s["mese_acquisto"] = random.choice([
"gennaio", "febbraio", "marzo", "aprile", "maggio"
])
# Guadagn
vend = s["percentuale_vendite"] = random.randrange(50, 80, 10)
ric = s["perc_ricarico"] = random.randrange(25, 50, 10)
costo_venduto = merci * vend / 100
prezzo_venduto = costo_venduto + costo_venduto * ric / 100
r = s["prezzo_venduto"] = str(prezzo_venduto)
if int(prezzo_venduto) == prezzo_venduto:
s["prezzo_venduto"] = str(r).split(".")[0]
else:
s["prezzo_venduto"] = r + "#" + r.replace(".", ",") + "#" + r + "0" + "#" + r.replace(".", ",") + "0"
return s
# ======================= TEXT OF THE
# EXERCISE ================
def printex() -> str:
''' Returns a string with the text of the exercise, chosen among 2 type of text
that contains random parts from a dictionary generated by genex()
the code will generate more solution, so that you can use the , or the .
if you are in a country where you use different type of sign for that
'''
s = genex()
x = random.choice([1,2])
match x:
case 1:
inp = """input("{random_start} valore delle merci acquistate il primo {mese_acquisto} al prezzo di {valore_merci} € delle quali il primo {mese_pag} si vende il {percentuale_vendite} % applicando un ricarico del {perc_ricarico} %.", "{prezzo_venduto}");""".format(**s)
case 2:
inp = """input("Sapendo che un'azienda ha acquistato merci il primo {mese_acquisto} pagandole {valore_merci} €, calcola quanto incasserà al momento del pagamento delle stesse concordato per il primo di {mese_pag}, data in cui ha venduto il {percentuale_vendite} % delle merci. Il ricarico sulle merci vendute è pari al {perc_ricarico} %", "{prezzo_venduto}");""".format(**s)
return inp
def show():
'''
Explanation of this code
1. Starting html code of the page with the script that
checks the solution.
2. After the script there is some html code to introduce
the exercises.
3. At the end of this script, before the call to this function show,
there is the call to printex for 10 time = 10 random exercises
Each time printex is called it choose 1 of 2 way of presenting the exercise.
The multiline strings takes random values generated by genex() a function
that creates and returns a dictionary with the keys corresponding to
the random parts of the text of the excercise.
'''
html = """
<style>
.fontbig {
font-size: 1.5em;
}
/**
Code By Web Dev Trick ( https://webdevtrick.com )
For More Source Code Visit Our Blog ( https://webdevtrick.com )
**/
body, html {
background: #ECEDEF;
margin-left: 10%;
margin-right: 10%;
padding: 0;
}
</style>
<!-- <html oncontextmenu="return false;"> -->
<script>
// ======================== CHECK ======================= >
function check(casella, giusta, num){
// the solutions are good both for low and capital letters
if (giusta.split("#").includes(casella.value)){
casella.style.background = 'yellow';
return casella.value;
}
else{
casella.style.background = 'red';
}
console.log(giusta);
// console.log(casella.value.split("#));
} // ====================================== CHECK === !
function print_it(parola){
if (soluzioni.innerHTML.includes(parola)){
}
else {
soluzioni.innerHTML += " - " + parola;
}
}
var countdom = 1;
function input(domanda, giusta){
var dom_h2 = "<table style='background:#fcab41;'><td><p class='fontbig' style='color: blue'>" + countdom++ + " " + domanda;
var part1 = dom_h2 + "<br><i style='color:red'>Prezzo delle merci vendute</i><br><input id='casella' class='fontbig' type=text class='t1' placeholder='?...' onchange=\\"if (check(this,'";
part1 += giusta + "')){print_it(this.value)};\\" style='text-align:right'/></center></p></table>";
document.write(part1);
}
x = document.getElementsByClassName('t1');
for (i of x){
i.value = "";
}
</script>
<h1>Fabbisogno 1</h1>
Il fabbisogno finanziario dipende anche dalle risorse finanziarie necessarie all'impresa per la gestione corrente. Controlliamo in questi esercizi se l'ammontare delle risorse derivanti dalle vendite sono sufficienti a far fronte ai debiti per gli acquisti. Di solito le imprese chiedono ai fornitori di poter pagare ad una certa data le merci acquistate, in modo da poter ottenere, nel frattempo, le risorse vendendo i prodotti acquistati. Probabilmente non riusciranno a vendere tutte le merci, ci sarà sempre una parte che rimane in magazzino, ma il prezzo di vendita è superiore a quello di acquisto, per cui, se il ricarico (l'aumento del prezzo rispetto a quello di acquisto) copre il costo delle merci invendute, l'impresa non avrà bisogno di ulteriori risorse finanziarie. Al contrario, dovrà chiedere un prestito oppure una ulteriore dilazione nel pagamento della differenza tra il valore delle merci acquistate e quello delle merci vendute.
<script>
"""
for x in range(10):
html += printex()
html += "</script>"
with open("fabbisogno1.html", "w", encoding="utf-8") as file:
file.write(html)
os.startfile("fabbisogno1.html")
show()