Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why wont this code run?

0 votes
asked Nov 6, 2019 by Zach

I want to get this code to run for my home work but when I run it nothing happens. the code is 

a = [4,8,15,16,23,42]

a[1:3]

5 Answers

+1 vote
answered Nov 7, 2019 by dheeraj (1,090 points)
a=[4,8,15,16,23,42]
b=a[1:3]
print(b)

output

[8, 15]
commented Nov 10, 2019 by Drilleba Joshua (290 points)
why do you think b=a[1:3]
commented Nov 11, 2019 by Dheeraj Dheeraj
You only asked for a[1:3] in question??m
commented Feb 3, 2020 by dheeraj (1,090 points)
otherwise you can take  directly as
print(a[1:3])
it will also work
+1 vote
answered Nov 7, 2019 by WYLDYR ?? (160 points)
This won't work in C++ if that is your langauge of choice.
+1 vote
answered Nov 7, 2019 by anonymous
You have to use the print command to display something. Right now you are not printing something.
+1 vote
answered Nov 7, 2019 by gameforcer (2,990 points)

Your code is not exactly wrong. It's just that you need to do something with that part of a list. Either assign it to a variable

suba = a[1:3]

 or print it out in console if you'd like

print(a[1:3])

0 votes
answered Nov 10, 2019 by Drilleba Joshua (290 points)
#include<iostream>using

namespace std;

int main()

{

cin>>"a=[4,8,15,16,23,42]" ;

function declaration

a[1:3]=b

cout<<"b"<< ;

Return 0;

}
commented Nov 11, 2019 by zaini 1 flag
cin function is not declare properly because in this function we get user input and write it without double quotes.function declaration word is not used in c++ because it a word to declare a variable.a[] funtion is writen in false way to aasign the value of b to the a[1:3].cout funtion is used but what we can ptint just word b? so the value must b used that we want to see in output.
commented Nov 12, 2019 by ANDRUA JOSHUA (160 points)
So, can i then write it in the format below;
#include <iostream>

using namespace std;

int main()

{
cin >>a=[4,8,15,16,23,42] ;

a[1:3]=b

cout <<b<< ;

Return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...