在Python中查找偶数 [英] Finding Even Numbers In Python

查看:180
本文介绍了在Python中查找偶数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python分配如下:编写一个完整的python程序,要求用户输入两个整数。然后程序输出 Both Even 如果两个整数都是偶数。否则程序输出 Not Both Even

I have a Python assignment that is as following: "Write a complete python program that asks a user to input two integers. The program then outputs Both Even if both of the integers are even. Otherwise the program outputs Not Both Even."

I计划使用if和else语句,但由于我正在使用两个必须是偶数而不是一个的数字,我该怎么做?

I planned on using an if and else statement, but since I'm working with two numbers that have to be even instead of one, how would I do that?

这是如果它是一个数字,我将如何做到这一点。现在如何添加用户输入的second_int ???

Here is how I would do it if it was one number. Now how do I add the second_int that a user inputs???

if first_int % 2 == 0:
    print ("Both even")
else: print("Not Both Even")


推荐答案

您仍然可以使用if else并使用if块检查多个条件

You can still use an if else and check for multiple conditions with the if block

if first_int % 2 == 0 and second_int % 2 == 0:
    print ("Both even")
else:
    print("Not Both Even")

这篇关于在Python中查找偶数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆