Jump to content

Photo

Python Help

python coding

  • Please log in to reply
8 replies to this topic

#1 pythoncoderforfun

pythoncoderforfun

    Bit

  • Members
  • 1 posts

Posted 14 December 2013 - 11:24 PM

I have to write a code doing this:
create a list named "hobbit". Add the characters in the following order: "Bilbo", "Gandolf", "Ori", "Thorin". Switch places with Bilbo and Ori. Then, print that list. 
Then, squeeze Ori's brother between Gandolf and Bilbo. Print the list again
Then, switch positions of Ori and Gandolf. Print the list again
 
I tried doing it, but I don't think I'm doing it correctly. 


#2 Guest_ElatedOwl_*

Guest_ElatedOwl_*
  • Guests

Posted 15 December 2013 - 01:47 PM

Can you post your current code please?



#3 Rejected

Rejected

    Megabyte

  • Banned
  • 453 posts
  • Locationhttp://www.crackhackforum.com/user-54122.html

Posted 12 January 2014 - 03:48 PM

seriously you should at least know that you have to post your own code


tumblr_my2mijmVhL1rb06tgo1_500.gif


#4 Guest_ElatedOwl_*

Guest_ElatedOwl_*
  • Guests

Posted 12 January 2014 - 04:51 PM

seriously you should at least know that you have to post your own code

No need to be rude about it. x:



#5 Rejected

Rejected

    Megabyte

  • Banned
  • 453 posts
  • Locationhttp://www.crackhackforum.com/user-54122.html

Posted 12 January 2014 - 05:43 PM

No need to be rude about it. x:

that's not rude unless you read it in a funny angry rude accent, try reading in a different way.

If this is the case you're the one full of negative energy not me. :P


tumblr_my2mijmVhL1rb06tgo1_500.gif


#6 seakingtheonixpected

seakingtheonixpected

    Gigabyte

  • Members
  • 986 posts
  • LocationSomewhere beyond the sea

Posted 12 January 2014 - 05:46 PM

I don't use Python, but what I imagine they want you to do is have variables with all those names in a list and then just change this list so the variables are printed in a different order.

 

Guessing the class is over now though, hope you passed!



#7 Nerdgirl11

Nerdgirl11

    Byte

  • Members
  • 43 posts

Posted 29 April 2014 - 11:29 PM

What version of Python are you using? 



#8 Sunbakedcow

Sunbakedcow

    Bit

  • Members
  • 5 posts

Posted 14 November 2016 - 04:26 PM

I don't use Python, but what I imagine they want you to do is have variables with all those names in a list and then just change this list so the variables are printed in a different order.

 

Guessing the class is over now though, hope you passed!

That is what you are​ supposed to do!


def complaint():

    print('A baked cow on the Sun. The cow is baked again by the Sun. The Sun ejects the double-baked cow. The overcooked animal ends up on my plate.')

 

def main():

    complaint()

main()

 


#9 Champion of Cyrodiil

Champion of Cyrodiil

    Gigabyte

  • Members
  • 776 posts
  • LocationVirginia

Posted 29 December 2016 - 05:12 PM

I have to write a code doing this:
create a list named "hobbit". Add the characters in the following order: "Bilbo", "Gandolf", "Ori", "Thorin". Switch places with Bilbo and Ori. Then, print that list. 
Then, squeeze Ori's brother between Gandolf and Bilbo. Print the list again
Then, switch positions of Ori and Gandolf. Print the list again
 
I tried doing it, but I don't think I'm doing it correctly. 

 

Although Thorin is not actually Ori's brother, which you alluded to without saying it specifically (https://thorinoakens...so-hot-dwarves/), For the sake of your code question I will answer based on what you're looking for.

 

# Declare the list and print to console
mylist = ["Bilbo", "Gandolf", "Ori", "Thorin"]
print(mylist)

# Get the Index of the two characters, and switch them.
a, b = mylist.index('Bilbo'), mylist.index('Ori')
mylist[b], mylist[a] = mylist[a], mylist[b]
print(mylist)

# Now "squeeze" Thorin between Gandolf and Bilbo, which only works because Gandolf is after Bilbo in this list.

mylist.insert(mylist.index('Bilbo'), mylist.pop(mylist.index('Thorin')))
print(mylist)
 

 

 
Result:

 

['Bilbo', 'Gandolf', 'Ori', 'Thorin']
['Ori', 'Gandolf', 'Bilbo', 'Thorin']
['Ori', 'Gandolf', 'Thorin', 'Bilbo']
 






Also tagged with one or more of these keywords: python, coding