【问题标题】:Python rookie prob type error mistakePython菜鸟prob类型错误错误
【发布时间】:2015-10-24 18:22:28
【问题描述】:
a=input("Enter your first number")
b=input("And your second one")
if a>b:
    if a%b==0:
        print("YES")
    else:
        print("NO")
else:
    if b%a==0:
        print("YES")
    else :
        print ("NO")

所以它一直给我一个 TypeError “TypeError:并非所有参数都在字符串格式化期间转换” 抱歉,我真的很陌生

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    这是因为input 函数返回一个String,所以你需要转换为intfloat,就像我在下面所做的那样。

    a = int(input("Enter your first number"))
    b = int(input("And your second one"))
    

    a = float(input("Enter your first number"))
    b = float(input("And your second one"))
    

    现在应该可以了。

    要了解有关这些内置函数的更多信息,请访问:

    https://docs.python.org/2/library/functions.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 2015-06-25
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多