friends... is sth wrong with this? | Sololearn: Learn to code for FREE!

-2

# friends... is sth wrong with this?

colors <- c("Red", "Green", "Blue", "Purple", "Black", "Yellow", "Orange", "Pink", "Brown", "White") print(colors[3])

10/18/2021 7:21:59 PM

Tree

+3

Tree Great so you have learnt many things 1 - in R language index starts from 1 not 0 2 - You have to read 1st line of the input means input[1] 3 - Don't write Hard Code value

+3

* Get input and store it in a variable * convert input to integer * use this number to index the vector

+3

Tree No that's not right. You have to do print(colors[n]) You have to pass user input n not hard code value ------And vector should be like this------ colors <- c("Red", "Green", "Blue", "Purple", "Black", "Yellow", "Orange", "Pink", "Brown", "White")

+3

Tree Why did you change input[1] to input[3] You don't need to change that

+3

Why input[3]? We need the 1st line of the input!

+2

type your code in code playground & save then share the link here Tree

+2

Tree you are getting the output Blue

+2

Is it the task from the R course? Look closely at the task description: the index is a number we input. So it is not always 3 but any number a user types in

+2

A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Lisa Adithya Keshav T thank you all very much. :) it worked. :)

+1

Purple Tree

+1

"Blue" is to be printed

+1

Then print(colors[2]) Tree

+1

that is green

+1

Tree 1 is red 2 is green 3 is blue & so on

+1

when i print 3 the output is Blue but it does not accept. don't know why

+1

https://code.sololearn.com/cK5oO7o7afno/?ref=app

+1

Tree Adithya Keshav T In R language index start from 1 not 0 so colors[3] = Blue

+1

You need to specify in the question that it's related to the R language.

0

i know. there is a green checkmark but it doesn't give 10 xp

0

yes it's R. it says "You are given a vector that contains color names. You need to take a number as input, and output the color name at that index. " A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟