Jump to content

Python help!

Go to solution Solved by Enderman,

 

 

thank you without you i couldn't get this done! :D you have made my day!

 

You're welcome! :)

okay guys so im learning python via codecadamy, i know it isnt brilliant and i know it isnt 3.3 but i need help with this piece of code it doesnt work on im stuck 

print 'Welcome to the Pig Latin Translator!'original = raw_input("Enter a word!")if len(original) > 0:    print "Please enter a word!"elif len(original) < 1:    print original

it doesnt seem to work, when i run it i get this 

Welcome to the Pig Latin Translator!Enter a word! James Please enter a word!None

and i need help please!

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/
Share on other sites

Link to post
Share on other sites

print 'Welcome to the Pig Latin Translator!'original = raw_input("Enter a word!")if len(original) < 0:    print "Please enter a word!"elif len(original) > 1:    print original

You need to reverse your > and  < symbols

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882497
Share on other sites

Link to post
Share on other sites

 

Not, sure what's wrong...

Try doing this instead:

len(str(original))

nope i tried it i get Oops, try again. Did you remember to use if and else in your code?

print 'Welcome to the Pig Latin Translator!'original = raw_input("Enter a word!")if len(original) > 0:    print "Please enter a word!"elif int(len(original)) < 1:    print original

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882503
Share on other sites

Link to post
Share on other sites

I found the problem and edited my first post :)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882515
Share on other sites

Link to post
Share on other sites

print 'Welcome to the Pig Latin Translator!'original = raw_input("Enter a word!")if len(original) < 0:    print "Please enter a word!"elif len(original) > 1:    print original

You need to reverse your > and  < symbols

 

tried your edit it says i have to use else and if :( 

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882520
Share on other sites

Link to post
Share on other sites

tried your edit it says i have to use else and if :(

change the elif to else

 

you can do 

else:        print original

instead of

elif len(original) > 1:     print original

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882526
Share on other sites

Link to post
Share on other sites

print 'Welcome to the Pig Latin Translator!'original = raw_input("Enter a word!")if len(original) < 0:    print "Please enter a word!"elif len(original) > 1:    print original

You need to reverse your > and  < symbols

 

tried your edit it says i have to use else and if :( 

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882538
Share on other sites

Link to post
Share on other sites

 

change the elif to else

 

you can do 

else:        print original

instead of

elif len(original) > 1:     print original

thankyou thankyou thankyou, it worked? may i ask why it is differnt block of code depending if its else of elif

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882566
Share on other sites

Link to post
Share on other sites

thankyou thankyou thankyou, it worked? may i ask why it is differnt block of code depending if its else of elif

The way you used elif in your first code would have worked too, I guess they're trying to teach you how to do it using else.

 

elif will basically do another "if" statement if the "if" statement before it failed

 

else just runs if all if/elif statements before it fail, and its easier because you dont have to type any conditions for it, aka you can skip the "original > 1" part

 

example:

x=5 if x==1:    print "x is 1"elif x==2:    print "x is 2"else:    print "x is neither 1 or 2"

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882590
Share on other sites

Link to post
Share on other sites

 

The way you used elif in your first code would have worked too, I guess they're trying to teach you how to do it using else.

 

elif will basically do another "if" statement if the "if" statement before it failed

 

else just runs if all if/elif statements before it fail, and its easier because you dont have to type any conditions for it, aka you can skip the "original > 1" part

 

example:

x=5 if x==1:    print "x is 1"elif x==2:    print "x is 2"else:    print "x is neither 1 or 2"

okay thanks im sorry to bug you but there is one more problem 

print 'Welcome to the Pig Latin Translator!'
 
original = raw_input("Enter a word!")
 
#this checks that it has more that 0 charractars and is just letters and no numbers
if len(original) < 0 and original.isalpha(): 
 
    print "Please enter a word!" 
 
else:
        print original im trying to use original.isalpha() but i cnat work out were pot put it 

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882630
Share on other sites

Link to post
Share on other sites

 

okay thanks im sorry to bug you but there is one more problem 

print 'Welcome to the Pig Latin Translator!'
 
original = raw_input("Enter a word!")
 
#this checks that it has more that 0 charractars and is just letters and no numbers
if len(original) < 0 and original.isalpha(): 
 
    print "Please enter a word!" 
 
else:
        print original im trying to use original.isalpha() but i cnat work out were pot put it 

 

try:

original = raw_input("Enter a word!") if original.isalpha():    print "Please enter a word!" else:    print original

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882671
Share on other sites

Link to post
Share on other sites

 

try:

original = raw_input("Enter a word!") if original.isalpha():    print "Please enter a word!" else:    print original

nope that doesnt work it justs prints what you type in 

print 'Welcome to the Pig Latin Translator!' original = raw_input("Enter a word!") #this checks that it has more that 0 charractars and is just letters and no numbersif original.isalpha():    print "Please enter a word!" else:    print original

and this is what i get Welcome to the Pig Latin Translator!

Enter a word! 123

123

None

 
 
and my error msg is Oops, try again. It looks like your code prints original ("123") when original includes non-alphabetical characters.

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882727
Share on other sites

Link to post
Share on other sites

 

Oh I messed. up, oops.

Switch around the " print original " and " print "Please enter a word!" " lines.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882741
Share on other sites

Link to post
Share on other sites

Oh I messed. up, oops.

Switch around the " print original " and " print "Please enter a word!" " lines.

 

thank you without you i couldn't get this done! :D you have made my day!

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882749
Share on other sites

Link to post
Share on other sites

 

 

thank you without you i couldn't get this done! :D you have made my day!

 

You're welcome! :)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
https://linustechtips.com/topic/212293-python-help/#findComment-2882759
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×