## brand new to python, program works but on testing has some problems

## brand new to python, program works but on testing has some problems

(OP)

I am new to python coding.

I am writing a program, a quiz that asks mathematical questions, it will ask 3 maths question and

randomly choose one of 4 operators, +,-,*,/

if the quizzer gets the question right the score will go up by one

I have tested this code many times but it has never done * or divide, it only does + and -

also sometimes the scoring works fine and other times the scoring does not work at all

I am writing a program, a quiz that asks mathematical questions, it will ask 3 maths question and

randomly choose one of 4 operators, +,-,*,/

if the quizzer gets the question right the score will go up by one

I have tested this code many times but it has never done * or divide, it only does + and -

also sometimes the scoring works fine and other times the scoring does not work at all

#### CODE --> python

import random #Defining Addition, Subtraction, Multiplication, Division def add(x1, x2): return x1 + x2 def sub(x1, x2): return x1 - x2 def mul(x1, x2): return x1 * x2 def div(x1, x2): return x1 / x2 #this function will return the users answer for the mathematical quiz question def check(x1,x2): answer = int(input("What is the value")) return answer def quiz(): #this will keep a count of how many times the question was asked, #the quiz will end when 3 questions have been asked count = 0; #this will keep a score of how many questions the player got right, score =0; while (count !=3): value = random.randint(0,3) if value == 0: x1 = int(input('First number?\n')) x2 = int(input('Second number?\n')) print("What is the answer of", x1, "+", x2, "= ") if add(x1,x2) == check(x1,x2): score +=1 count +=1 elif value == 1: x1 = int(input('First number?\n')) x2 = int(input('Second number?\n')) print("What is the answer of", x1, "-", x2, "= ") if sub(x1, x2) == check(x1,x2): score +=1 count +=1 elif value == 2: x1 = int(input('First number?\n')) x2 = int(input('Second number?\n')) print("What is the answer of", x1, "-", x2, "= ") if mul(x1, x2) == check(x1,x2): score +=1 count +=1 elif value == 3: x1 = int(input('First number?\n')) x2 = int(input('Second number?\n')) print("What is the answer of", x1, "-", x2, "= ") if div(x1, x2) == check(x1,x2): score +=1 count +=1 if count == 3: print("You have scored ", score, "out of 3") exit() quiz()

## RE: brand new to python, program works but on testing has some problems

print("What is the answer of", x1, "-", x2, "= ")

## RE: brand new to python, program works but on testing has some problems

however the divide does not work properly, how can i change the code so it will work to accept a division value

## CODE --> python

## RE: brand new to python, program works but on testing has some problems

It's integer number division for example: 5 / 2 = 2

## RE: brand new to python, program works but on testing has some problems

1. Function div() should return real number

## CODE

2. function answer() should not convert everything to integer, i.e.:

## CODE