+ 1

How Can I Fix The Code ?

I want to print "Try Again" in this code if the user doesnt write an integrer between 0 and 20. The first print works though but i dont want to print everything at once and want to learn a new technique... https://code.sololearn.com/cNIcue4m1DIK/?ref=app

1st Dec 2018, 11:49 PM
Necati Lök
Necati Lök - avatar
1 Réponse
+ 2
What I understand by your problem statement is i) If the user enters a number €[0,20] and the number is composite then yes gets printed ii)if the user enters a number €[0,20] and the number is not composite then no gets printed iii)if user enters a number < 0 and > 20 then Try again gets printed find below the modification of your code: num = (int)(input()) composite = [4,6,8,9,10,12,14,15,16,18,20] if(num in composite): print('yes') elif(num not in composite and (num >= 0 and num <=20 )): print('no') else: print('Try Again')
2nd Dec 2018, 12:09 AM
Rishi Anand
Rishi Anand - avatar