Skip to content

Instantly share code, notes, and snippets.

@dcbriccetti
Last active November 16, 2021 18:11
Show Gist options
  • Save dcbriccetti/3d2dd01617d6cb4d6474d0599813ef94 to your computer and use it in GitHub Desktop.
Save dcbriccetti/3d2dd01617d6cb4d6474d0599813ef94 to your computer and use it in GitHub Desktop.
for n in range(10):
print('hello')
print('world!')
for n in range(1, 11):
print(n)
# Display the integers from -2 to 2
for n in range(-2, 3):
print(n)
# Display the integers from 101 to 110
for n in range(101, 111):
print(n)
# Display the even integers from -2 to 4
for a in range(-2, 5, 2):
print(a)
# Display the odd integers from -1 to 3
for a in range(-1, 4, 2):
print(a)
# Display the integer multiples of 3 up to 9
# Display the sequence 4, 2, 0, ..., -8
# Use -2 for the step (third argument to range)
for num in range(4, -9, -2):
print(num)
print(list(range(10))) # Extra bonus material
score = 100
if score > 90:
print('You get an A')
words = ['bird', 'car', 'basket']
words2 = 'bird car basket'.split(' ')
print(words == words2)
# Print all the words that start with a 'b'
# Combining a loop with if
for word in words:
# Only print those that start with 'b'
if word.startswith('b'):
print(word)
# % modulo, aka remainder operator
# Should just print the even numbers
for n in range(10):
if n % 2 == 0:
print(n)
# Do you want help with the sum 1 to n?
def main():
n = 10
total = 0
for num in range(n + 1):
total += num
print(total)
main()
print(sum(range(11))) # super-bonus material 😀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment