Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easier solution#14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
madamak wants to merge4 commits intorealpython:master
base:master
Choose a base branch
Loading
frommadamak:patch-1
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
# At the start all cats are hatless.
cats = [False]*101

# We do a loop over each step size from 1 to 100
for step_size in range(1, 100 + 1):

# For each step size we calculate how many cats we are going to visit
cats_to_visit = 100 // step_size

# We only loop over cat indices that are a multiple of our step size
for i in range(1, cats_to_visit + 1):

# We reverse the hat status for each cat we loop over
cats[i*step_size] = not cats[i*step_size]

# Print the list of cats that have a hat
for i in range(101):
if cats[i]:
print(f"Cat {i} has a hat!")

[8]ページ先頭

©2009-2025 Movatter.jp