在第一部电话()之后为什么它不起作用?

时间:2016-11-10 19:27:16

标签: python

{"207.5,1", "373,2", "278.5,3", "9.1,1",
"9.1,9", "134,4", "277,5", "674,7", "58.5,9"}

2 个答案:

答案 0 :(得分:1)

缩进块,更加小心!

def phone():
    import webbrowser
    print("Do you have an iphone or samsung?")
    answer = input ('iphone/samsung:')
    if answer == "iphone":
        print("what type of iphone?")
        answer = input ('5, 6 or 7:')
    if answer == "samsung":
        print("what type of samsung do you have?")
        answer = input ('s5, s6 or s7:')
x = input("press enter and type in your answer. phone(), tablet() or console() ")
if x == 'phone()':
    phone()
elif x == 'tablet()':
    tablet()
elif x == 'console()':
    console()

答案 1 :(得分:1)

基本上,你拥有的是......

def foo():
    print("stuff")

answer = input("type foo()")

answer == "foo()"True

你从未打电话给foo(),但你只是把它作为一个字符串输入。

你需要运行它。

exec(answer)

但是exec非常糟糕,所以相反,您应该使用ifelif来调用相应的函数。

if answer == 'foo()': 
    foo()