Doubts of python

Asked

Viewed 421 times

1

I’m new to python, and I’m looking to make a system, where you fill out a questionnaire, and consequently it already prints in html to just paste in the forum. What I rode was the following:

from datetime import datetime

now=datetime.now()

ano=now.year

mes=now.month

dia=now.day

aprovados=input('Digite o(s) nick(s) do(s) aprovado(s): ')

naprovados=int(input('Digite o número de aprovados: '))

reprovados=input('Digite o nome do(s) aluno(s) reprovado(s): ')

nreprovados=int(input('Digite o número de alunos reprovados: '))

nalunos=naprovados + nreprovados

inicio=input('Digite o horário do início da aula: ')

termino=input('Digite o horário do término da aula:  ')

nsala=input('Digite a sala utilizada: ')

ag=input('Digite o nick do Guia (Se não houver digite "X"): ')

obs=input('Digite sua observação da aula')

print('[b]Nick do guia:[/b] [color=#0000ff] [b]WellersonOP [/b] [/color]')

print('[b]Patente e página: [/b] [color=#0000ff] [b]Aspirante [/b] [/color] [color=#ff0000][b][16/12-01][/b][/color]')

print('[b]Data da aula:[/b] [color=#0000ff] [b]{}/{}/{}[/b][/color]'.format(dia, mes, ano))

print(' ')

print('[color=#009900][b]Nick dos aprovados:[/b][/color] [b]{}
[/b]'.format(aprovados))

print('[color=#009900][b]Número de aprovados:[/b][/color] [b]{}[/b]'.format(naprovados))

print('[color=#009900][b]Número de civis:[/b][/color] [b]{}[/b]'.format(nalunos))

print(' ')

print('[color=#ff0000][b]Nick dos reprovados:[/b][/color] [b]{}[/b]'.format(reprovados))

print('[color=#ff0000][b]Número de reprovados:[/b][/color] [b]{}[/b]'.format(nreprovados))

print(' ')

print('[b]Horário de início:[/b] [b]{}[/b]'.format(inicio))

print('[b]Horário de término:[/b] [b]{}[/b]'.format(termino))

print('[b]Número da sala utilizada:[/b] [b]{}[/b]'.format(nsala))

print(' ')

print('[b]A.G:[/b] [b]{}[/b]'.format(ag))

print('[b]Observação:[/b] [b]{}[/b]'.format(obs))

print('[b]Sua assinatura:[/b]')

And works perfectly, however, I wanted to know how to make the days instead of appearing 1/6/2018, appear 01/06/2018, but that do not affect when it was 10/11/2018 for example, because if I add the 0 in front of the date print, when I put on that date, would appear 010/011/2018. Could someone give me the command for this along with the explanation?

I would also like to put in AG, if nobody typed anything, automatically appeared a custom text, could also explain me this?

2 answers

2

Make a concatenation of the day before printing, where you check if the printed value is less than or equal to day "9". Only values equal or lower can get a "zero" in front.The values of 10 above (31) remain normal. (I am not a Python user. I am an Object Pascal user. Check syntax details)

if dia<=9:dia = str("0" + dia)

1

On the line that prints the date, try this way:

print('[b]Data da aula:[/b] [color=#0000ff] [b]{}[/b][/color]'.format(now.strftime('%d/%m/%Y')))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.