Hello again friends and neighbors. I come (again) humbly asking for help with a script. I have written some math quiz scripts for my grandkids( the add 1 is posted below) to help them learn basic math skills. I am fortunate enough to have a gifted granddaughter( 8 years old) and she loves working with these scripts. I have decided to 'turn up the heat' on her. The script I've posted below uses a function to do the actual problem, checks if correct and enter into proper variable. I want to restrict the time she has to answer to, say, 90 seconds. If she answers, it should stop the timer and check answer. If she fails to answer in the 90 seconds, then I want to 'echo "sorry, you have taken too long to answer. This problem will be counted incorrect."' and the add 1 to $I and loop through to next problem. I don't know if I worded this in a way you can understand my goal, so if more info is needed, please ask. I need this for a much larger version of this, 5 levels, each harder than the previous level, with 5th level being timed. As always, any help would be appreciated.
Code:
#!/bin/bash
function_1 () {
x=$[RANDOM%$R1] y=$[RANDOM%$R2]
sum=$(($x + $y))
echo "What is $x + $y?"
read answer
echo "You answered $answer."
if [[ $answer = $sum ]] ;
then echo "That is correct!! Great job."
C=$(( $C + 1 ))
else
echo "Sorry,that is not right. The correct answer is $sum."
I=$(( $I + 1 ))
fi
}
now=$(date +"%m-%d-%y_%I:%M_%p")
echo "This test was taken $now"
I=0
C=0
echo "Hello, why don't you tell me your name."
read name
name=$name
echo "Hello $name. My name is Alex and I'll be giving you your test today."
file=$name-$now
touch /home/charles/Tests/$file.txt
echo "OK $name, how many problems would you like to do today?"
read number
TP=$number
echo "Very good, we will do ${TP} problems today."
echo "What's the biggest you want your numbers to be?"
read limit
R1=$limit
R2=$((R1+1))
echo "OK, your numbers will not be larger than $limit."
echo "OK, let's get started."
PC=1
while [[ $PC -le $TP ]]
do
PC=$(( $PC + 1))
function_1
done
score=$(( ($C*1000/$TP+5)/10 ))
echo "OK, let's see how you did today."
sleep 1
echo "On todays quiz, you got $C problems correct, you got $I wrong."
echo "Your score today is $score."
cp /home/charles/Tests/temp_file.txt /home/charles/Tests/$file.txt
sleep 3
echo "Would you like to print a copy of the test?"
read answer
answer=${answer^^}
answer=${answer:0:1}
if [[ ${answer} = 'Y' ]] ;
then lp /home/charles/Tests/${file}.txt
echo "It should be printing."
echo "I'll see you next time."
sleep 3
exit
else echo "OK. The file is saved and can be printed anytime.
I'll see you next time."
fi
exit
Please, if you modify this script, comment out my lines you replace, but leave them there so I can study what you have done. Asking for help does no good if I come back next month to ask for the same helpagain. I'm trying to learn it, not have someone write it for me. Thank you for any help you give.
Bookmarks