I'm a complete novice to python and sage so I need some help and clarification on the steps all the way through. This is a question concerning game theory.
First I will describe the algorithm and then I will propose a solution the best I can.
The algorithm:
I want to start the program with a random variable from 1-100. This variable will be defined 'S'. I also want to define a set of variables 'C' which can be deducted from S every turn, this set is {1,2,3,4,5,6} (in other words the user and computer can deduct 1, 2, 3, 4, 5 or 6 from S. If variable S is divisible by 7 (e.g. 21), then print: "I lose". If not, the game can begin.
Let's say that the random variable turns out to be 20. The player is now prompted to enter a number within the range of C. When the player has entered the number, I want the program to deduct that number from S, so if the player enters 4 (a legal move), S is then 20-4=16. The computer then calculates mod(S,7) and finds out that modulo 16,7 is 2 so it deducts 2 from S, in other words, 16-2=14. If the player enters a number which results in S being divisible by 7, such as 6 (20-6=14) then the computer simply deducts 1 and attempts to get to such a number again next round.
The game continues until the computer eventually wins as the player is eventually placed at 7 and has to deduct a number which the computer can finish with (user deducts 6, computer deducts the last one and wins). Print: "I win".
So like I said, I have literally no experience in python and sage so I can only go by my (limited) java experience:
I would attempt to establish a variable S with some 'ran' element (no idea what it's called in python). I would then attempt something like:
if S%7=0 then print "I lose"
else
prompt "Pick a number between 1 and 6, those included".
Declare user input as variable U.
Do S-U=S
Now do S-S%7=S
Now I want the program to realize when S=7
and then print: "You lose". If you can help me go all the way, though, that would be great.