Skip to content

Forum in maintenance, we will back soon 🙂

Notifications
Clear all

Loops quiz

4 Posts
2 Users
3 Reactions
33 Views
(@jay-kim)
Posts: 35
Trusted Member Customer
Topic starter
 

 

I asked chat gpt but not sure it was right.

 

Give me the answer for it.

 

Still not sure how I use and ask chat gpt.

 

So far not easy course to me..

 
Posted : 07/10/2023 1:20 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

Hi friend, no worries, we all started like this, I am here to help you understand. 

here is a sample code:

# List of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Loop through the list
for number in numbers:
# Check if the number is even
if number % 2 == 0:
print(f'{number} is even')
else:
print(f'{number} is odd')

 

This program iterates over every number in the numbers list and checks if it is even by using the modulus operator (%). If the remainder when the number is divided by 2 is 0, then the number is even. If the remainder is anything else (in this case it can only be 1), the number is odd.

 

Does this help?

 

 
Posted : 07/10/2023 1:36 pm
SSAdvisor reacted
(@jay-kim)
Posts: 35
Trusted Member Customer
Topic starter
 

@admin I think you're too smart to teach it to me. you can't remember beginners' mind anymore..

 
Posted : 07/11/2023 12:13 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

mmm, let me try once again.

imagine you have a bag containing 10 balls. on each ball, there is a number written. (1 to 10)

now we want to classify the balls into two other bags, one coating balls with odd numbers, and the other with even numbers.

so we pick up the first ball, and we look at the number, for example we find it is 5. we want to know now if 5 is odd or even.

what we do is divide 5 by 2 (5/2)

we get 2, and the remainder 1. (remember grade 3 decision)

so if we have a remainder, the number is odd, if the remainder is 0, the number is even, so 5 is odd.

 

we repeat the process on all balls in the bag till we finish.

 

does this make sense?

 

 

 

 

 
Posted : 07/12/2023 10:45 am
SSAdvisor and Jay Kim reacted
Share:
[the_ad_group id="312"]