"argument of type 'int' is not iterable" appears when matching multiple conditions in Python

The error message appears as
Insert image description here

n=input("要转换的温度选项;1,摄氏度转华氏度;2,华氏度转摄氏度:")
if n in (1:
    S=input("摄氏度为:")
    H=1.8*float(S)+32
    print("华氏度为:",format(H))
elif n in (2):
    H=input("华氏度为:") 
    S=(float(H)-32)/1.8
    print("摄氏度为:",format(S))


Solution:
Change "if n in (1)" to "if n in ['1']"
Insert image description here

n=input("要转换的温度选项;1,摄氏度转华氏度;2,华氏度转摄氏度:")
if n in ['1']:
    S=input("摄氏度为:")
    H=1.8*float(S)+32
    print("华氏度为:",format(H))
elif n in ['2']:
    H=input("华氏度为:") 
    S=(float(H)-32)/1.8
    print("摄氏度为:",format(S))


Guess you like

Origin blog.csdn.net/qq_44918057/article/details/128919214