Https://www.codecademy.com/courses/learn-python/lessons/loops/exercises/create-your-own?action=resume_content_item


#1

https://www.codecademy.com/courses/learn-python/lessons/loops/exercises/create-your-own?action=resume_content_item

Hi, I’m trying to figure out what I’m doing wrong in my else statement in my code. All the characters in my string do not equal zero; therefore, it should only be printing “Be brave. Do great things.” to my console, correct? Why does it include “Always”?

Here is the code:
string= ‘Be brave. Do great things!’
for x in range(9):
if x != 0:
print string
else:
print “Always”


#2

sorry can’t access it


#3

please copy paste your code to the forum, the url will just give us access to the exercise but load our own code (checks for signed in user)


#4
string= 'Be brave. Do great things!'
for x in range(9):
  if x != 0:
    print string
  else:
    print "Always"

#5

Try putting parenthesis around string.


#6

range just produces a list:

print range(9) # outputs: [0, 1, 2, 3, 4, 5, 6, 7, 8]

which does include a zero. You are not doing anything with characters in your string


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.