Comparing input or variables is a quite a common task to do when creating programs.
In Python
it can be done in a lot of ways, this example code below shows how it’s being
done using “if else” and “or” statement.
Here’s the
example code below:
#Get user
input requires Python 3
input1 = input("1. Type something to test this out : ")
input2 =
input("2. Type something to test this out : ")
input3 =
input("3. Type something to test this out : ")
checkinput1
= 0
checkinput2
= 0
checkinput3
= 0
noinput = 1
#int(input1)
convert the input1 string to an integer
if
(int(input1) > 40):
checkinput1 = "1"
elif (
int(input2) > 40):
checkinput2 = "1"
elif (
int(input3) > 40):
checkinput3 = "1"
else:
noinput = 0
if
(checkinput1 or checkinput2 or checkinput3 == "1"):
print("At lest 1 input is more than
40")
else:
print("All input are less than
40")
One scenario that this can be used is when you got 3 or more inputs on an html page that requires only 1 input to be filled up from all the inputs that you asked the user to filled up. Of course, after the ‘if statement’ don’t just use print but execute some codes that needs to be done if a specific condition is meet or not.
================================
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment