Python-输入正确答案时出错

时间:2018-10-26 14:30:52

标签: python

当我选择问题3时,即使我确实输入了正确的答案(value_c * value_d,它也告诉我这是不正确的。帮助吗?

import random

value_a = random.randint(100, 999)
value_b = random.randint(100, 999)
value_c = random.randint(21, 89)
value_d = random.randint(21, 89)
value_e = random.randint(81, 100)
value_f = random.randint(81, 100)

print('''Straight to the point. Pick an option.
1. 2 numbers with 3-digit values added.")
2. 2 numbers with 3-digit values added and then multiplied by 2.
3. 2 numbers with 2-digit values and less than 89 multiplied.
4. 2 numbers with 2-digit values and between 80 and 100 multiplied.
5. 3 random numbers added or subtracted.''')

question = int(input("Choose the type of question you want: "))
print("\n")

if question == 1:
    answer = int(input(str(value_a) + " + " + str(value_b) + " : "))
    if answer == value_a + value_b:
        print("Dayum quicc mafs, trie again if yu wand.")
    else:
        print("Bed mafs.")

elif question == 2:
    answer = int(input( "(" + str(value_a) + "+" + str(value_b) + ")"+ "*2" + " : "))
    if answer == 2*(value_a + value_b):
        print("Dayum quicc mafs.")
    else:
        print("Bed mafs, trie again.")

这是我的答案似乎永远不正确的部分:

elif question == 3:
    answer == int(input(str(value_c) + " * " + str(value_d) + " : "))
    print(value_c, value_d)
    if answer == value_c * value_d:
        print("Dayum quicc mafs.")
    else:
        print("Bed mafs, trie again.")

1 个答案:

答案 0 :(得分:0)

在Python中,单个=表示赋值。您使用了一个双精度==,它是一个等于运算符。请勿混淆两者,因为未分配答案。下面,我将==更改为=

elif question == 3:
    answer = int(input(str(value_c) + " * " + str(value_d) + " : "))
    print(value_c, value_d)
    if answer == (value_c * value_d):
        print("Dayum quicc mafs.")
    else:
        print("Bed mafs, trie again.")