Quantcast

Jump to content


Photo

Help with python

http://www.codecademy.com/

  • Please log in to reply
21 replies to this topic

#1 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 07 June 2014 - 08:12 AM

im taking a class on the website listed in the tag and i was wondering if you guys could help me

 
  1. On line 3, create the variable my_stringand set it to any string you'd like.
  2. On line 4print the length ofmy_string.
  3. On line 5print the .upper() case version of my_string.
 

 i cant remember/figure out how to create the variable my_string



#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 07 June 2014 - 08:13 AM

my_string = "blah"



#3 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 07 June 2014 - 08:15 AM

# Write your code below, starting on line 3!
 
my_string = "Thanks"
print "my_string"
print len(my_string)
print my_string.upper()
basically my code would end up like this?


#4 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 07 June 2014 - 08:16 AM

You'd just need print my_string without the "".



#5 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 07 June 2014 - 08:42 AM

k Thanks ill post if i run into any other issues 


Can any one list the comparators  and what they mean real quick


Edited by MichaelA, 07 June 2014 - 08:44 AM.


#6 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 07 June 2014 - 08:51 AM

http://www.codecadem...inner-BxUFN/1/1



#7 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 08 June 2014 - 01:10 PM

Let's practice with and. Assign each variable to the appropriate boolean value.

  1. Set bool_one equal to the result of Falseand False
  2. Set bool_two equal to the result of -(-(-(-2))) == -2 and 4 >= 16**0.5
  3. Set bool_three equal to the result of 194 != 300 / 10 / 10 and False
  4. Set bool_four equal to the result of -(1**2) < 2**0 and 10 % 10 <= 20 - 10 * 2
  5. Set bool_five equal to the result of Trueand True

i dont understand a single part of this i would love for someone to explain and help me thanks:D

@waser lave


Edited by MichaelA, 08 June 2014 - 01:21 PM.


#8 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 08 June 2014 - 01:37 PM

 

Let's practice with and. Assign each variable to the appropriate boolean value.

  1. Set bool_one equal to the result of Falseand False
  2. Set bool_two equal to the result of -(-(-(-2))) == -2 and 4 >= 16**0.5
  3. Set bool_three equal to the result of 19% 4 != 300 / 10 / 10 and False
  4. Set bool_four equal to the result of -(1**2) < 2**0 and 10 % 10 <= 20 - 10 * 2
  5. Set bool_five equal to the result of Trueand True

i dont understand a single part of this i would love for someone to explain and help me thanks:D

@waser lave

 

 

Ew, they really made it hard. In real life, what asshat writes code that obfuscated? :p

 

 

Anyway, let's go through it step by step:

 

The 'and' keyword compares two boolean (True/False) statements. If one is False, both are False.

 

1) 'False and False' = False

 

2) 'True and False' = False

 

3) 'True and True' = True

 

(The above aren't the answers to your questions, or, at least, I haven't tried to make them as such)

 

For each of your questions/tests, just make each side of the 'and' keyword either 'True' or 'False', then apply the expression to the rules I just laid out. :)

 

You could even just copy + paste it into the command line and it'd give you the answer. :)


Edited by Irradium, 08 June 2014 - 01:44 PM.


#9 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 08 June 2014 - 04:08 PM

Break It Down

Now let's take what we've learned so far and write a Pig Latin translator.

Pig Latin is a language game, where you move the first letter of the word to the end and add "ay." So "Python" becomes "ythonpay." To write a Pig Latin translator in Python, here are the steps we'll need to take:

  1. Ask the user to input a word in English.
  2. Make sure the user entered a valid word.
  3. Convert the word from English to Pig Latin.
  4. Display the translation result.

^^^^^^^

Instructions
 I got the first line of code but im confused af
 
word = raw_input("Input a word in English")

bump for help :l


Edited by MichaelA, 08 June 2014 - 03:36 PM.


#10 Not2EXceL

Not2EXceL
  • 10 posts

Posted 08 June 2014 - 04:13 PM

I don't use python as I can use lua or perl instead. But can't your just str[index] in python? Also string concatation is a subject to look up. Also I misspelled concat terribly I think.

#11 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 08 June 2014 - 04:51 PM

 

Break It Down

Now let's take what we've learned so far and write a Pig Latin translator.

Pig Latin is a language game, where you move the first letter of the word to the end and add "ay." So "Python" becomes "ythonpay." To write a Pig Latin translator in Python, here are the steps we'll need to take:

  1. Ask the user to input a word in English.
  2. Make sure the user entered a valid word.
  3. Convert the word from English to Pig Latin.
  4. Display the translation result.

^^^^^^^

Instructions
 I got the first line of code but im confused af
 
word = raw_input("Input a word in English")

bump for help :l

 

 

I'm not Kway, but I want to help again. :)

 

So, you've got the 

word = raw_input(string)

 - which is prompting the user for a string of bytes (so you know you'll get a string)

 

Then, I presume when it tells you to check it's a valid word, you'll want to make sure it's made out of alphabetical characters.

But you'd need to use regex, and until it clicks, regex is really confusing. By all means, try it out, it's very useful! :D

 

So, for now, you could just make sure it's not an empty string, like so:

if word: # 'if word' is essentially 'if word is True'
    # continue with code
else:
    # prompt for input again

Then do some string slicing and concatenation of 'word', like so:

>>> word = "welcome"
>>> changed_word = word[1:] + word[0:1] + "ay"

(Hope you understand what's going on there, just say if you don't. :) )

 

And then, the most complicated step:

print(changed_word)

Hope this helped! :D



#12 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 08 June 2014 - 04:53 PM

I'm not Kway, but I want to help again. :)

 

So, you've got the 

word = raw_input(string)

 - which is prompting the user for a string of bytes (so you know you'll get a string)

 

Then, I presume when it tells you to check it's a valid word, you'll want to make sure it's made out of alphabetical characters.

But you'd need to use regex, and until it clicks, regex is really confusing. By all means, try it out, it's very useful! :D

 

So, for now, you could just make sure it's not an empty string, like so:

if word: # 'if word' is essentially 'if word is True'
    # continue with code
else:
    # prompt for input again

Then do some string slicing and concatenation of 'word', like so:

>>> word = "welcome"
>>> changed_word = word[1:] + word[0:1] + "ay"

(Hope you understand what's going on there, just say if you don't. :) )

 

And then, the most complicated step:

print(changed_word)

Hope this helped! :D

0.o This stuff frys my brain but is so intresting 



#13 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 08 June 2014 - 05:00 PM

0.o This stuff frys my brain but is so intresting 

 

Oh yeah, those two attributes commonly combine.

 

Any particular part that's confusing that we/I can help with? Or do you just need some time to work on it?



#14 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 08 June 2014 - 05:02 PM

Oh yeah, those two attributes commonly combine.

 

Any particular part that's confusing that we/I can help with? Or do you just need some time to work on it?

Um pm me if you want to and if you could explain in depth whats going on i would be so grateful 



#15 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 08 June 2014 - 05:03 PM

Um pm me if you want to and if you could explain in depth whats going on i would be so grateful 

 

Sure. :)



#16 Not2EXceL

Not2EXceL
  • 10 posts

Posted 08 June 2014 - 06:03 PM

@Irradium
Why would you slice a single char? Just get from the index.

#17 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 08 June 2014 - 06:16 PM

Eh, you could do it either way, I guess I was just in 'slice' mode there. :p

#18 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 10 June 2014 - 10:22 AM

Instructions

This time we'll give the expected result, and you'll use some combination of boolean operators to achieve that result.

Remember, the boolean operators are and,or, and not. Use each one at least once!


 

Instructions

This time we'll give the expected result, and you'll use some combination of boolean operators to achieve that result.

Remember, the boolean operators are and,or, and not. Use each one at least once!

 

Would this be the results

# Use boolean expressions as appropriate on the lines below!
 
# Make me false!
bool_one = (2 <= 2) and "Alpha" == "Bravo"  # We did this one for you!
 
# Make me true!
bool_two = (3 != 4) 
 
# Make me false!
bool_three = ( 1 == 2)
 
# Make me true!
bool_four = ( 3 > 2)
 
# Make me true!
bool_five = ( 2 < 3)

Instructions
  1. On line 2, fill in the if statement to check if answer is greater than 5.
  2. On line 4, fill in the elif so that the function outputs -1 if answer is less than 5.
  3. I have this
def greater_less_equal_5(answer):
    if  2 ** 3:
        return 1
    elif 2 - 3:          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
 any help please?

Edited by MichaelA, 10 June 2014 - 10:23 AM.


#19 Not2EXceL

Not2EXceL
  • 10 posts

Posted 10 June 2014 - 10:27 AM

 

Instructions

This time we'll give the expected result, and you'll use some combination of boolean operators to achieve that result.

Remember, the boolean operators are and,or, and not. Use each one at least once!


Would this be the results

# Use boolean expressions as appropriate on the lines below!
 
# Make me false!
bool_one = (2 <= 2) and "Alpha" == "Bravo"  # We did this one for you!
 
# Make me true!
bool_two = (3 != 4) 
 
# Make me false!
bool_three = ( 1 == 2)
 
# Make me true!
bool_four = ( 3 > 2)
 
# Make me true!
bool_five = ( 2 < 3)

Instructions
  1. On line 2, fill in the if statement to check if answer is greater than 5.
  2. On line 4, fill in the elif so that the function outputs -1 if answer is less than 5.
  3. I have this
def greater_less_equal_5(answer):
    if  2 ** 3:
        return 1
    elif 2 - 3:          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
 any help please?

 

Seems like part of the post ghosted.
if: check if answer is greater than 5
elif: check if answer is less than 5
 


Edited by Not2EXceL, 10 June 2014 - 10:28 AM.


#20 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 10 June 2014 - 10:29 AM

Seems like part of the post ghosted.
if: check if answer is greater than 5
elif: check if answer is less than 5
 

for if i have this

def greater_less_equal_5(answer):
    if  2 ** 3:
        return 1                                
for elif i have this 
  elif 2 - 3:          
        return -1


#21 Not2EXceL

Not2EXceL
  • 10 posts

Posted 11 June 2014 - 04:44 PM

 

for if i have this

def greater_less_equal_5(answer):
    if  2 ** 3:
        return 1                                
for elif i have this 
  elif 2 - 3:          
        return -1

 

sigh you have to edit the statements
if answer > 5
elif answer < 5



#22 MichaelA

MichaelA
  • Very Hard to Shoot

  • 484 posts


Users Awards

Posted 11 June 2014 - 05:50 PM

sigh you have to edit the statements
if answer > 5
elif answer < 5

ik i fixed it the day of




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users