Last active
September 27, 2021 07:58
-
-
Save phoebe-leong/b63c0d3da73fd64dd5ca22493c853b96 to your computer and use it in GitHub Desktop.
pythonquiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rm quiz.py &> /dev/null | |
touch quiz.py | |
read -p "Enter your name/nickname: " name | |
echo "# Generated by $name using a shell script" > quiz.py | |
printf "# Source code located at https://gist.github.com/phoebe-leong/b63c0d3da73fd64dd5ca22493c853b96\n\n" >> quiz.py | |
echo "score = 0" >> quiz.py | |
echo "if __name__ == \"__main__\":" >> quiz.py | |
input="start" | |
total=0 | |
newline="\n" | |
while [ "$input" != "end" ] | |
do | |
read -p "Enter a question or \"end\": " input | |
if [ "$input" == "end" ] | |
then | |
break | |
fi | |
printf "\tprint(\"Question \" + str(int($total) + 1) + \":\")\n" >> quiz.py | |
printf "\tanswer = input(\"$input \")\n\n" >> quiz.py | |
read -p "Enter the answer to the question: " input | |
printf "\tif answer == \"$input\":\n" >> quiz.py | |
printf "\t\tscore += 1\n" >> quiz.py | |
((total++)) | |
done | |
printf "\tprint(\"You got \" + str(score) + \" question/s correct out of $total\")" >> quiz.py | |
printf "Quiz successfully generated! Run \"python3 quiz.py\" to execute it\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment