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

gamestop xbox 360 hard drive slim how to remove a stripped computer screw how to jailbreak ipod touch 3rd gen windows genuine remover for windows 7 ultimate ios 5.1 jailbreak replacing xbox 360 hard drive windows 7 build 7601 not genuine how to fix problem xbox 360 slim 320gb hard drive how to reset bios password laptop how to open ica file where to catch a bagon in emerald 1024 mb equals how many gb afterglow xbox 360 controller driver unifi ap without controller download command and conquer generals zero hour crack how many megabytes is in a gig xbox 360 wireless controller with play and charge kit gta 4 gamestop xbox 360 how many megabytes is 6 gigabytes how much is an xbox 360 controller at gamestop pc dongle for xbox 360 controller xbox one kinect gamestop star wars the force unleashed input codes ps3 play and charge kit xbox 360 pc 2.5 mm headphone jack adapter pc headset adapter for xbox 360 gamestop gta 5 xbox 360 1000 megabytes to gigabytes where to catch bagon in emerald how to jailbreak ipad 5.1.1 xbox 360 slim hard drive install ios 5.1.1 untethered jailbreak


×