# Problem with if statement branching after Python input

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

``````a=input("What do you want to calculate? 1. Molar concentration 2. PPM concentration 3. Percent concentration")

if a==1:
b=input ("What is the concentration of the solution you want to calculate?")
c=input ("How many moles of solution do you want to calculate?"")
d=c/b
print("The molar concentration is ""d,"" and //kg.")

elif a==2:
e=input ("What is the mass of the solute you want to calculate?"")
f=input ("What is the mass of the solution you want to calculate?"")
g=e/f*10^6
print("PPM concentration is ""g,"PPM.")

elif a==3:
h=input ("What is the mass of the solute you want to calculate?"")
i=input ("What is the mass of the solution you want to calculate?"")
k=h/i*100
print("% concentration is ""k",%""

``````

There is no error, but if you actually execute it, the first INPUT door pops up, but if you enter 1, it doesn't pop up after that. Please let me know where the error is.

python input

2022-09-20 15:39

` #1 a=int("What do you want to calculate?" 1. Molar concentration 2. PPM concentration 3. Percent concentration")

#2 a = map(int,input("What do you want to calculate? 1. molar concentration 2. PPM concentration 3.percent concentration") `

Both forms are possible.

As explained above, the return of input() is always a string. Therefore, expressions belonging to the if, elif, and else statements must also be modified to int(input()) or float(input()).

2022-09-20 15:39

It is recommended that you always memorize the return of Python `input()` as a string.

`if int(a) == 1:` Please convert all integers.

2022-09-20 15:39

Popular Tags
python x 1522
android x 362
c x 361
java x 353
javascript x 303
php x 126
swift x 112
mysql x 92
r x 87
html x 51