Jump to content
  • Announcements

    • alpenwasser

      Please Use CODE Tags 31 Jan 2016

      Welcome to the Programming and Software Design Section,

      When asking for help with programming issues, please use the code tags to enclose your code, it makes things much more easily readable for the people trying to help you, thus improving your chances of actually getting help.
        To add code tags, click the <> button on the editor toolbar, then enter your code in the code editor that appears. If you are on a mobile device, or prefer to use BBCode, you can use [code] // Your code here // It will be syntax highlighted, though not necessarily corectly. [/code] (but the code editor is more consistent and less buggy).
Antman507

I'm super rubbish at this stuff

Recommended Posts

Posted · Original PosterOP

im currently doing programming at school, and i am so bad at it, could any one help and explain what are the outputs of (using python) :

 

print(highscores[3])

 

print(highscores[0] - highscores[4])

Link to post
Share on other sites

Well i'm not good at it either but it looks to me you are using values from an array.

https://en.wikipedia.org/wiki/Array_data_structure#One-dimensional_arrays


If you want my attention, quote meh! D: or just stick an @samcool55 in your post :3

Spying on everyone to fight against terrorism is like shooting a mosquito with a cannon

Link to post
Share on other sites

The first one will print item 4 (computers count from 0 so 0,1,2,3) in the list highscores 

 

the second will display item 1 minus item 5

 

e.g 

highscores = [1,2,3,4,5]

it will show

 

4

-4

Link to post
Share on other sites
2 hours ago, Antman507 said:

print(highscores[3])

This line prints a 4th element (number, string, whatever you store at that position) of "highscores" array

2 hours ago, Antman507 said:

print(highscores[0] - highscores[4])

This one prints the result of the subtraction in parentheses (first element - fifth element)

Link to post
Share on other sites

Many will disagree with my recommendation but for starting the SYNTAX of python, codecademy.com is pretty good. 

 

It doesn’t teach you good practices nor thinking. Only the syntax and what things mean. I think it’s good for starting. 


PC game list: 

Build Plan: 

 

Link to post
Share on other sites
23 hours ago, Antman507 said:

im currently doing programming at school, and i am so bad at it, could any one help and explain what are the outputs of (using python) :

 

print(highscores[3])

 

print(highscores[0] - highscores[4])

I'll explain it from a higher level of abstraction so hopefully you can actually understand what you're doing here. You have an array called highscore. It is important to know that this is an array, and not a list, set, collection, etc. In python (and many other languages) you can use indexing to access data within the array. As others have mentioned, arrays start counting at 0.

 

So in the first line of code, you're calling the print function to print whatever data is in the 4th 'slot' in the highscores array. We don't know the contents of the array, so it could be numbers, strings, objects, or a mixture of data. So the next line could do a few different things. If the data in the first and fifth slots are numbers, the result of the substraction will be printed. If they are of different types, and an operation is not defined for substraction you will get a TypeError.

 

 

Edit:: It's also a good idea to familiarize yourself with the different data structures (Array, List, Set) as they appear in many languages, and their operations are usually very similar / the same across languages.


NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

Link to post
Share on other sites
21 hours ago, fpo said:

Many will disagree with my recommendation but for starting the SYNTAX of python, codecademy.com is pretty good. 

 

It doesn’t teach you good practices nor thinking. Only the syntax and what things mean. I think it’s good for starting. 

It's what I used to learn the python syntax. I did a year of creating scripts for people over forums and from that you learn how to make code neater and more maintainable. 

 

Sadly not used python for a while as my work uses node. I do miss it.


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

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!

Sign in

Already have an account? Sign in here.



  • Recently Browsing 0 members

    No registered users viewing this page.

Last Topics

how much does gta v cost at gamestop unifi ap range guitar controller pc how to bypass bios password asus notebook recovery opening ica file 3.5 mm to 2.5 mm adapter xbox 360 windows 7 ultimate not genuine how to get kingdra in pokemon emerald how to find bios password for laptop afterglow xbox 360 controller on pc xbox 360 120gb hard drive gamestop mainboard socket 775 how do i sync contacts to icloud c&c generals zero hour how much megabytes in 1 gigabyte sword art online episode 1 english dubbed command & conquer generals shockwave linksys smart wifi router n750 asus overclocking tool drilling out a stripped screw xbox 360 charge controller how to charge a wireless xbox 360 controller use xbox 360 controller on pc linksys ea2700 manual xbox 360 core hard drive windows 7 build 7601 not genuine fix megabytes equals gigabytes how many mb is in a gigabyte what does 1gb equal in mb


×