简体   繁体   English

我想编写一个代码,当一个数字等于某事时说些什么,但是当它大于或小于该数字时,做其他事情

[英]I want to make a code that says something when a number is equal to something, but when it is bigger than or less than that number do something else

This code started out as a joke, but has become something a little more… I am trying to make this code, but I cannot figure out how to make the code for Pluto print when the number they put in is '9'.这段代码一开始只是个玩笑,但后来变得有点……我正在尝试制作这段代码,但是当他们输入的数字是“9”时,我不知道如何让 Pluto 打印代码。 But the only thing I can get is the code for the if statements… when I want it to print the elif statement… If anyone knows the fix for this, let me know!但我唯一能得到的是 if 语句的代码……当我希望它打印 elif 语句时……如果有人知道解决这个问题的方法,请告诉我!

while True:
  amnt = input('Okay, how many planets are in this solar sytem? ')
  help = int(amnt)
  ast = int(amnt) * 89990189
  howMany = print('That means there are roughly ' + str(ast) + ' asteroids in this solar system!')
  if help >= 8:
    howMany
    break
  if help <= 100000:
    howMany
    break
  elif help == 9:
    print('Um, Pluto isn\'t a planet, you know...')
    howMany
    break
  else:
    print('Please try again.')

This is the solution I have found, for your pluto planet:这是我为您的冥王星找到的解决方案:

while True:
  amnt = input('Okay, how many planets are in this solar sytem? ')
  help = int(amnt)
  ast = int(amnt) * 89990189
  howMany = print('That means there are roughly ' + str(ast) + ' asteroids in this solar system!')
  if help >= 8:
    howMany
    if help == 9:
      print('Um, Pluto isn\'t a planet, you know...')
      break
  break
  if help < 100000:
    howMany
    break
  else:
    print('Please try again.')

You have already checked for planets above or equal to 8 so that condition is True and in that you will again check that value (amount) is equal to 9 or not in the same loop.您已经检查了大于或等于 8 的行星,因此条件为 True,并且您将在同一循环中再次检查值(数量)是否等于 9。 It is called nested loop.它被称为嵌套循环。 I have used it.我已经用过了。 check it out.一探究竟。

暂无
暂无

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

相关问题 是否有一个命令,以便当某个东西比答案少3或3个时它会做什么? - Is there a command so that when something is 3 less than or 3 more than the answer it would do something? 如何将有效位数限制为*而不是使用str.format()或f-strings? - How do I limit the number of significant digits to *not more* than something with str.format() or f-strings? 如果第 n 个数字,则做某事 - Do something if nth number 如果get_lengths(k)大于20,则执行其他操作 - if the get_lengths(k) more than 20 then do something else do something 如果有数字,我如何添加一个返回字符串的 if 语句,如果有数字以外的其他内容则停止? - How can I add a if statement that goes back in string if there is a number, and to stop if there is something other than a number? 我可以使用其他东西来缩短代码而不是在 python 中使用多个 IF 吗? - Can I use something else to shorten the code rather than using mutiple IF in python? 写入期望类型不是浮点数的数据库时如何处理 NaN 值? - How to handle NaN values when writing to a database which expects something else than type:float? 蟒蛇:我试图匹配数字,但它匹配其他 - Python: I am trying to match number but it is matching something else 当我处理大于99的数字时,我的代码开始产生不合逻辑的答案 - My code starts yielding illogical answers when a I deal with number bigger than 99 如何做到这一点,如果列表中的任何变量大于 integer,它会打印出一些东西,否则它会打印出其他东西? - How to make it so if any variable in a list is greater than an integer, it will print out something, else it will print out something else?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM