-2
print('='*50)
print('Digite X para calcular o que você não sabe em um P.A')
print('='*50)
a1=int(input('Digite o 1° Termo:'))
r=int(input('Digite a RAZÃO da P.A:'))
an=int(input('Digite o ULTIMO termo:'))
n=int(input('Digite a quantidade de termos:'))
if n=='x':
numerotermos=(an-a1+r)/r
print('O numero de termos da P.A é {:.0f}'.format(numerotermos))
if an=='x':
ultimotermo=a1+(n-1)*r
print('O ultimo termo da sua P.A é {:.0f}'.format(ultimotermo))
I’m still in the process. The problem is how to put an 'X'' (um termo desconhecido)
for the program to calculate, and I would need it at the same time to be 'str' and 'int'.
I’m still in the basic course of python, so any suggestions to improve the code is welcome.
thanks in advance!
If you want the input to be the character 'x' then you should not try to convert the input to int before ensuring that such input is effectively a numeric string.
– anonimo
A P.A. is a sequence in which the difference between a term
N
and its backgroundN - 1
is always a constantr
. And to calculate a P.A. we use the formula(An = A1 + (n - 1) * r)
. So we must know what we actually have to calculate. IfAn
orA1
orn
orr
.– Solkarped
In this case, we must first know what we want to calculate and then derive the formula and calculate the desired variable.
– Solkarped