This is my first question here (yay!). This may seem like a silly question but in a if statement like the one below what does % mean?
if n % i == 0:
print("hi")
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The ‘%’ is the modulus operator. It’s the remainder after integer division.
5/2 is 2 remainder 1. So 5%2 is 1.
In the specific case of comparing to zero, it checks divisibility. So n%i will be equal to zero if and only if n is evenly divisible by i.