0
I was creating a program that defined which was the age of 4 people if she was male, until then I was able to make the codes that define who is older but when I try to define that the person has to be of sex "M" The male program simply gives me 0 as a response, this only occurs when I add the following commands
(and a2 == "M":, and B2 == "M":, and C2 == "M", and D2 == "M":). I’m learning to code in python
a = str(input("Insira seu nome: "))
a1 = int(input("Insira a sua idade: "))
a2 = str(input("Informe seu sexo [M/F]: ")).upper()
print(" ")
b = str(input("Insira seu nome: "))
b1 = int(input("Insira a sua idade: "))
b2 = str(input("Informe seu sexo [M/F]: ")).upper()
print(" ")
c = str(input("Insira seu nome: "))
c1 = int(input("Insira a sua idade: "))
c2 = str(input("Informe seu sexo [M/F]: ")).upper()
print(" ")
d = str(input("Insira seu nome: "))
d1 = int(input("Insira a sua idade: "))
d2 = str(input("Informe seu sexo [M/F]: ")).upper()
maior_idade_homem = 0
if a1 > b1 and a1 > c1 and a1 > d1 and a2 == "M":
maior_idade_homem = a
elif b1 > a1 and b1 > c1 and b1 > d1 and b2 == "M":
maior_idade_homem = b
elif c1 > a1 and c1 > b1 and c1 > d1 and c2 == "M":
maior_idade_homem = c
elif d1 > a1 and d1 > c1 and b1 > c1 and d2 == "M":
maior_idade_homem = d
print("O homem da maior idade é {}".format(maior_idade_homem))
Why the first time you requested sex you used
upper()
and the other times did justupper
, without the parentheses?– Woss
It is worth remembering that
input
returns a string, then dostr(input(...))
is unnecessary, just use theinput(...)
and there, you’ll have the string.– hkotsubo
As previously mentioned: place
upper()
. Another thing, your lastif
that is likeelif d1 > a1 and d1 > c1 and d1 > c1 and d2 == "M":
... I think it should beelif d1 > a1 and d1 > b1 and d1 > c1 and d2 == "M":
. Notice that you usedd1 > c1
twice.– Paulo Marques
Those parodies are wrong even Woss, vlw by warning
– Gustavo Dos Santos Capeletti
okay hkotsubo, vlw by reminder
– Gustavo Dos Santos Capeletti
I checked here Paulo Marques and really was wrong, already corrected but the code continues to 0 as a result
– Gustavo Dos Santos Capeletti