Note that there are some explanatory texts on larger screens.

plurals
  1. POOriginal number of card in Python (Find missing card)
    text
    copied!<p>I'm trying to find out the original card that was present, but is now missing.</p> <p>To go more into depth, I'll provide a few examples:</p> <blockquote> <p>Example 1</p> <p>How many cards originally? 4</p> <p>What card do you still have? 1</p> <p>What card do you still have? 4</p> <p>What card do you still have? 2</p> <p>You are missing card 3</p> <p>Example 2</p> <p>How many cards originally? 2</p> <p>What card do you still have? 2</p> <p>You are missing card 1</p> </blockquote> <p>The problem I am experiencing, is: a) I'm not sure how I can produce raw inputs based on the initial card number, and b) My algorithm for the solution has flaws and I don't know how to overcome it.</p> <p>Here is my partial code:</p> <pre><code>orig = int(raw_input("How many cards originally? ")) card1 = int(raw_input("What card do you still have? ")) card2 = int(raw_input("What card do you still have? ")) card3 = int(raw_input("What card do you still have? ")) calculation = card1 + card2 + card3 print calculation - orig </code></pre> <p>However, it does not meet to the standards I want.</p> <p>Thanks so much in advance if you can help me out. It would be great if someone could write a solution to this or perhaps even guide me to do so.</p> <p>PS. If I haven't explained it that well, this is the question set that I was told to answer: Write a program to work out which card you have misplaced. Your program should first ask the user for how many cards you originally had. Your program should then ask you to enter each of the cards you still have, one number per line. Your program should then print out the value of the missing card.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload