简体   繁体   English

我在 python 中的数学测验有问题

[英]I have a problem with a math quiz in python

I am very new at python and i just wanted to make a pprogramm with a question how much is 23*10?我对 python 很陌生,我只是想用一个问题来制作一个 pprogramm,23*10 是多少? and if the user answers 230 it will print true but if not it would print false and i dont know how to ... this is my first attempt如果用户回答 230 它将打印 true 但如果不是它会打印 false 我不知道如何...这是我的第一次尝试

Question = input("How much is 23 * 10? ") if Question == "230":print("True")

It is pretty much what you made, lacking indentation and the else .这几乎就是你所做的,没有缩进和else Also, I'm adding int() before input() because otherwise, the value provided will be considered as a string instead of a number.另外,我在input() int()之前添加int()因为否则,提供的值将被视为字符串而不是数字。 It doesn't make much difference if you are then comparing it with a string "230" but I just thought I'll change it a bit to show you another perspective.如果您将它与字符串"230"进行比较并没有太大区别,但我只是想我会稍微改变一下以向您展示另一个视角。

question = int(input("How much is 23 * 10? "))

if question == 230:
    print("True")
else:
    print("False")

As I explained before, if you do not wish to use int then you must compare the value to a string:正如我之前解释的,如果您不想使用int那么您必须将值与字符串进行比较:

question = input("How much is 23 * 10? ")
if question == "230":
    print("True")
else:
    print("False")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM