Forums Search Login Register
New Posts Todays Posts Find Users Posts Unanswered Threads Help Mark Forums as Read

Thread Options  Subscribe to this thread Subscribed Users  Add Reply 
Posts: 1,362
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.


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 ))
                echo "Sorry,that is not right. The correct answer is $sum."
                I=$(( $I + 1 ))

now=$(date +"%m-%d-%y_%I:%M_%p")
echo "This test was taken $now"

echo "Hello, why don't you tell me your name."
        read name

echo "Hello $name. My name is Alex and I'll be giving you your test today."

touch /home/charles/Tests/$file.txt

echo "OK $name, how many problems would you like to do today?"
        read number
echo "Very good, we will do ${TP} problems today."

echo "What's the biggest you want your numbers to be?"
        read limit
echo "OK, your numbers will not be larger than $limit."

echo "OK, let's get started."

        while [[ $PC -le $TP ]]
        PC=$(( $PC + 1))

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
                if [[ ${answer} = 'Y' ]] ;
                        then lp /home/charles/Tests/${file}.txt
                        echo "It should be printing."
                        echo "I'll see you next time."
                        sleep 3
                else echo "OK. The file is saved and can be printed anytime.
                I'll see you next time."
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.
07-22-2021, 06:51 PM
Subscribe to this thread Subscribed Users  Add Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Every time initramfs is regenerated, I can't boot danastacrrzynnt 0 1 Yesterday 06:35 PM
Last Post: danastacrrzynnt
  [ubuntu] Stuck on GNU Grub minimal bash AshelyP1955 0 1 Yesterday 12:26 PM
Last Post: AshelyP1955
  TTL mode is activated in my sysytem at the login time orileekidd 0 1 07-28-2021 07:31 AM
Last Post: orileekidd
  [SOLVED] usb stick problem tintan253 0 3 07-25-2021 09:26 PM
Last Post: tintan253
  [SOLVED] How can I easilly check cpu temp ljackilawrhhhek 0 3 07-22-2021 09:55 PM
Last Post: ljackilawrhhhek
  disk full after usage of script that used a default cache directory dgalinaalvaradoj 0 7 07-19-2021 08:13 AM
Last Post: dgalinaalvaradoj
  [SOLVED] Partioning large drives orileekidd 0 5 07-16-2021 07:48 AM
Last Post: orileekidd
  [xubuntu] xgamma does not dim monitor when called from bash script rdaniellabarryr 0 3 07-15-2021 08:29 PM
Last Post: rdaniellabarryr
  [SOLVED] How to install curl thorhelicalremedial 0 8 07-14-2021 11:18 AM
Last Post: thorhelicalremedial
  [SOLVED] Installed Ubuntu 21.04 Now I have problems with OBS. Bergerac 0 11 07-09-2021 10:49 AM
Last Post: Bergerac

Forum Jump:

User(s) browsing this thread: 1 Guest(s)

Contact Us Privacy Policy Top RSS
Forum Software By: MyBB, © 2002-2021