← All Class 11 programs

Search in a tuple

Class 11 Computer Science · Tuples · Write the program · 4 marks

  1. Read the question and the sample tests.
  2. Write your Python program in the editor.
  3. Run Code to check it on the sample tests (no marks).
  4. Submit Answer for evaluation: hidden tests award the marks. Nothing is saved here.

Question

Write a program that reads a tuple of integers and a value to search for. If the value is present, print its position counting from 1 (its first occurrence); otherwise report that it is not present. Input: two lines: the integers separated by spaces, then the value to search for. Output: exactly one line, either Found at position P or Not present

Sample tests

Use these examples to check your program. Your output must match the Expected Output exactly.

Sample 1
Sample Input
4 8 15 16
15
Expected Output
Found at position 3
Sample 2
Sample Input
4 8 15 16
5
Expected Output
Not present

Evaluation: when you submit, your program is also checked against 4 hidden tests that you cannot see. Marks come from the hidden tests only. Each test you pass earns its marks, so a partly correct program gets part marks. Prompt text passed to input() is not counted as output.

Your program

Write the complete program. It must read any input itself and print the result.

Write the whole program, including any import lines it needs. The editor starts empty; Reset Code clears it. Submit your answer before leaving the page.

Loading Python…
Approach (open it after you have tried)

The membership operator "in" checks whether the value is in the tuple at all. If it is, T.index(key) gives the index of its first occurrence, counted from 0, so 1 is added to give the position counted from 1. Calling index() for a missing value would raise an error, which is why "in" is tested first.

Practise all 65 Class 11 programs

This page has 10 programs. The complete Class 11 Python Lab has 65, and keeps your best score and chapter progress.

Other Class 11 programs: Simple interest · Grade from marks · Prime or composite · Alternating series · Right triangle of stars · Palindrome string · Linear search in a list · Character frequency with a dictionary · Circle with the math module

CodeBuddy
Hi there! 👋 I'm CodeBuddy, your KV Coders assistant.

To help me give you the most accurate answers, please select your class and subject below, or just type your question!
Buddy is typing...