2
I am working with a table that shows the number of vacancies offered, candidates enrolled and enrolled in higher education courses. I want to make a program that allows the visualization of this data from the input user (say he wants to know how many vacancies were offered and how many people entered in law courses... he type "Right" and the program shows these numbers).
I managed to make the codes work, but only one by one, in three different programs. Is it possible to unite these three in one code?
1)
import csv
curso_desejado = input('Qual o curso? ')
vagas = 0
arquivo = open('oks4c.csv', encoding='utf8')
for registro in csv.reader(arquivo):
vagas_oferecidas = registro[1]
curso = registro[0]
if curso == curso_desejado:
vagas += int(vagas_oferecidas)
print(f'O número de vagas oferecidas em {curso_desejado} é: {vagas}')
2)
import csv
curso_desejado = input('Qual o curso? ')
inscritos = 0
arquivo = open('oks4c.csv', encoding='utf8')
for registro in csv.reader(arquivo):
candidatos_inscritos = registro[2]
curso = registro[0]
if curso == curso_desejado:
inscritos += int(candidatos_inscritos)
print(f'O número de inscritos em {curso_desejado} é: {inscritos}')
3)
import csv
curso_desejado = input('Qual o curso? ')
ingressos = 0
arquivo = open('oks4c.csv', encoding='utf8')
for registro in csv.reader(arquivo):
ingressantes = registro[3]
curso = registro[0]
if curso == curso_desejado:
ingressos += int(ingressantes)
print(f'O número de ingressantes em {curso_desejado} é: {ingressos}')
Was open
ingressantes =
– NoobSaibot
Yes, thank you, corrected.
– Maniero
Perfect! It worked. Taking advantage, would it be feasible to do an operation (to be shown in a fourth print line) showing that the X tickets of such a course represent that Y% of the total vacancies offered was occupied? Or Python percentage is complicated?
– Guilherme
@William Percent is simple in any language, just know arithmetic. This is another problem.
– Maniero
In fact, it’s a simple @Maniero calculation! I thought I’d need to do some sort of more complicated arrangement. But I was left wondering where to put it. In which part of the code I could insert the line
porcentagem = ingressos / vagas * 100
or betterporcentagem = int(ingressos / vagas) * 100
for what, in addition to the number of vacancies, registered and tickets, downstairs the program also showed the percentage of filled vacancies? I tried to use these commands, but the lineprint(f'O percentual de vagas preenchidas em {curso_desejado} é: {porcentagem}')
does not show the result...– Guilherme