vendredi 17 avril 2020

checking conditions of string index

am having trouble checking the conditions over the string index

string = '1234'

I have two conditions as below

Conditions : 3rd and 4th position should be  34, or 2nd position should be 2

code :

if x[2] =='3' and x[3] == '4' or x[1] == '2' : 
     print('correct')
else:
     print('wrong')

here, am not able to understand how does it satisfy the condition. 3rd and 4th together could be written separably as in the above code.

Please suggest

Aucun commentaire:

Enregistrer un commentaire