A basic Python Programming Challenge Last Updated : 11 Apr, 2025 Comments Improve Suggest changes Like Article Like Report This time we are not going to go into any theoretical stuff. Some months ago, I wrote a program in Python for my students so that they can practice basic BODMAS questions. The purpose was that the program should generate random set of questions (number of questions to be entered by the user) and then check whether the entered answer is correct or not. Now, obviously it was quite easy for me to code, But, the thing was I had to ensure that 5/2 = 2.5 is as much correct as 2.500. So, I just couldn’t go and match two strings. I had to come up with a different solution. Just to have fun and see if any of my students or volunteers could come up with a vulnerability in the program, I specifically wrote a weak program. Now, I have modified the program to make it easier for you all to identify the mistakes and the vulnerabilities in it.Now, here is what I want you to do:Don’t look at the code. Just compile it, run it and see if you can figure out the vulnerabilities in 1the code.If you can’t figure out the vulnerabilities in step 1 or even if you did, go and take a look at the program code and try to figure out what are the things you missed! Once you are done, please comment what you think are the vulnerabilities in the code and how will you correct them! Here we go!! Given Input: 36-1Program for the small basic python Challenge Python ## Note: This program has been modified a bit for ## GeeksForGeeks article import random,operator print ('===========================================') def randomCalc(i,j): ops = {'+':operator.add, '-':operator.sub, '*':operator.mul, '/':operator.truediv } num = [1,2,3,4] num1,num2 = num[i],num[j] op = (list(ops.keys()))[i] answer = round(ops.get(op)(num1,num2),3) print('What is {} {} {}?\n'.format(num1, op, num2)) return answer def askQuestion(i): answer = randomCalc(i,i+1) guess = float(input()) return guess == answer,answer def quiz(numOfQues): print('\nWelcome. This is a '+str(numOfQues)+' question math quiz.') print('Your answer should be correct to three decimal places.\n') score = 0 for i in range(numOfQues): correct,ans = askQuestion(i) if correct: score += 1 print('Correct!\n') else: print('Incorrect! The correct answer is ' + str(ans)+'\n') return ('Your score was {}/'+str(numOfQues)).format(score) # Driver Code print (quiz(3)) Output: =========================================== Welcome. This is a 3 question math quiz Your answer should be correct to three decimal places. What is 1 + 2? Correct! What is 2 * 3? Correct! What is 3 - 4? Correct! Your score was 3/3 Comment More infoAdvertise with us Next Article A basic Python Programming Challenge K kartik Follow Improve Article Tags : GBlog Python Computer Subject Python Programs secure-coding +1 More Practice Tags : python Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Python List Creation Programs Python provides multiple ways to create lists based on different requirements, such as generating lists of numbers, creating nested lists, forming lists of tuples or dictionaries, and more.This article covers various ways to create lists efficiently, including:Generating lists of numbers, strings, a 2 min read Program to create grade calculator in Python Given different scored marks of students. We need to find a Grade Calculator in Python. The test score is an average of the respective marks scored in assignments, tests, and lab work. The final test score is assigned using the below formula. 10% of marks scored from submission of Assignments 70% of 4 min read Python Tips and Tricks for Competitive Programming Python Programming language makes everything easier and straightforward. Effective use of its built-in libraries can save a lot of time and help with faster submissions while doing Competitive Programming. Below are few such useful tricks that every Pythonist should have at their fingertips: Convert 4 min read Python List and Tuple Combination Programs Lists and tuples are two of the most commonly used data structures in Python. While lists are mutable and allow modifications, tuples are immutable and provide a stable structure for storing data. This article explores various programs related to list and tuple combinations, covering topics like:Sor 6 min read Like