Given a string of integers separated by commas, convert the string into a tuple where each element is one of the integers from the string. Retrieve the n-th element from the tuple you created. Use 0-based indexing for getting the n-th element. First line of the input contains the string of integers and the second line contains the index 'n'. Write a program to scan these two lines as input, and print the n-th element from the tuple you created.
Tuple
Retrieving n-th element from a tuple created from a string
Report a typo
Sample Input 1:
2,3,5,7,11
3Sample Output 1:
7Sample Input 2:
13,23,31,43,89,151
2Sample Output 2:
31Write a program in Python 3
# Required Library
import sys
def main():
# Read two lines from standard input
str_nums = sys.stdin.readline().strip()
index = int(sys.stdin.readline().strip())
# Now you need to create a tuple from the string of integers in `str_nums`
# After creating the tuple you need to print the n-th element from the tuple.
# Note: You need to use 0-based indexing to get the n-th element.
# Call main function
if __name__ == "__main__":
main()
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.