Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
num=["a","b","c","d"]
num[0]=int(input("enter an int for a: "))
num[1]=int(input("enter an int for b: "))
num[2]=int(input("enter an int for c: "))
num[3]=int(input("enter an int for d: "))

def finding_max():
   for i in num:
        max > i
        print({i})
finding_max()


What I have tried:

python Program to find largest element in an array
Posted
Updated 16-Jul-20 6:15am
v2

Yes, you can use an if clause (and any other) anywhere in your code. The only stipulation is that it must be logical (in order to work) and conform to the rules of the language. And the easiest way to confirm such a question is to write some code and try it.
 
Share this answer
 
Quote:
Can I use if in for loop in Python
Yes.
Python
for i in num:
   if i > max:
      max = i
print (max)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900