2 weird 2 b true


#1



so i'm stuck at 10: ending up and yeah.


everytime i try it it comes out liek this:
Enter a word: supercalifragilisticexpialidocious
Traceback (most recent call last):
File "python", line 5, in
NameError: name 's' is not defined


yeah... weird eh?

ladies and gentlemen, i present to you, THE ANNOYING CODE.


pyg = 'ay'
original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = s[1:len(word)]



if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'

so if you can help, that'd be great.

cheers,
GuyIncognito


#2

problem1.
new_word = s[1:len(word)]

where this s (variable that you're slicing) come from ?

Prolem2.
You're missing this...

do reply what are you getting after shooting these errors! :slight_smile:


#3

"where this s (variable that you're slicing) came from ?"
sorry but i use proper grammar here. what do you of mean by this sentence?


#4

Pardon me for my poor grammar use.! :slight_smile:

"where this s (variable that you're slicing) came from ?"

Lets understand this in next example..

name = "xkcdxkcd12344321"
# I have to slice name but instead..

slice_part = nome[3:4]

# there is no nome but name in this code so it will throw an error!

#5

so... how about this?

pyg = 'ay'
original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = word + first + pyg
new word = s[1:]



if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'

should work, right?


#6

Nope,It'll not!

If we slice something, It should be present in the code!
Can you find what value s stores here ?

hint**
I also marked out 3 main problems that'll cause it to not run!

further hint**
As instruction says we have to slice new_word and store the value to itself (Re-assign)!


#7

i give up. how about this.

pyg = 'ay'
original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:]



if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'

#8

Just two small modifications...

if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'

updated** @xkcdxkcd12344321
Instead printing original we have to print the new_word
and in the else part print the string 'empty' !
do reply if you get it or not! :slight_smile:


#9

guess what, this came up:
File "python", line 13
SyntaxError: 'return' outside function


#10

I've updated my post(few mins ago) and said to use print


#11

:sailboat: thanks, and the sailboat there because it can


#12

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