+ 2

Solved-Python Beginner - Strings List Problem "Write a program that takes an input string and outputs the 3rd character of the s

Hi! So the problem is "Write a program that takes an input string and outputs the 3rd character of the string". This is from 'Time to Practise' for Python Beginner. My attempt: str = input() print(str[3]) When I ran the above code, the result showed that Test Case 1 is correct but Test Case 2,3,4 are wrong. Not sure what I'm missing, appreciate someone helping :) --- solution Mistake was that it said "3rd element" which means its supposed to be 2, not 3! :)

2nd Nov 2021, 2:32 AM
Noshin Anwar
Noshin Anwar - avatar
12 Réponses
+ 3
actually the index starts from 0, 1, 2, 3, .............so on the third character will be index of 2. try it
2nd Nov 2021, 2:42 AM
Krishnam Raju M
Krishnam Raju M - avatar
+ 6
Try it str = input() print (str[2])
30th Jan 2022, 9:21 PM
Avrian Shandy
Avrian Shandy - avatar
+ 3
Try this str = input() print (str[2])
26th Jul 2022, 10:47 AM
Cristiano Ronaldo
Cristiano Ronaldo - avatar
+ 2
I just now came back to delete this question because realised my mistake was that it should have been 2 instead of 3! Thanks for the help :)
2nd Nov 2021, 2:43 AM
Noshin Anwar
Noshin Anwar - avatar
+ 2
Try this str = input() print (str[2])
10th Jan 2022, 1:33 PM
Maruf Ahammed Mondal
Maruf Ahammed Mondal - avatar
+ 2
str=input() print(str[2])
31st Mar 2022, 9:56 AM
Ahmed Salouh Abdelmoried
+ 1
str = input() print (str[2])
31st Mar 2022, 9:33 PM
Abdelkhalek Nael Ahmad Allan
Abdelkhalek Nael Ahmad Allan - avatar
+ 1
str=input() print(str[2])
22nd Oct 2022, 12:33 PM
Nagasiva Vakadani
Nagasiva Vakadani - avatar
+ 1
t = input() print(t[2]) also right answer
30th Oct 2022, 1:15 PM
Abhishek Maheshwari
Abhishek Maheshwari - avatar
+ 1
This code is for all cases str=input() if len(str)>=3: print(str[2]) else: print("Error")
25th Nov 2022, 10:33 PM
Diana Grigoryan
0
Str = input() Print (str[2])
25th Oct 2023, 9:50 AM
Azmeera Shanthi
Azmeera Shanthi - avatar
- 1
here is the correct answer: str = input() print (str[2])
29th Jun 2022, 11:14 AM
Hamza Limam Eibba
Hamza Limam Eibba - avatar