logo
down
shadow

How can limit how many times an operator shows up in my maths quiz in vb?


How can limit how many times an operator shows up in my maths quiz in vb?

Content Index :

How can limit how many times an operator shows up in my maths quiz in vb?
Tag : vb.net , By : gcomstock
Date : November 24 2020, 01:01 AM

I wish did fix the issue. Here's an example of what I mentioned in the comments. It builds a list of the desired number of operations in equal quantities, then shows how to pull a random one from that list:
Public Class Form1

    Private Operations As New List(Of String)

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Operations = CreateOperations(10)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Operations.Count > 0 Then
            Dim operation As String = NextRandomOperation()
            Debug.Print(operation)
        Else
            Debug.Print("No more operations in list!")
        End If
    End Sub

    Private Function CreateOperations(ByVal NumberOperations As Integer) As List(Of String)
        Dim operators() As String = {"+", "-", "X"}
        Dim operations As New List(Of String)
        While Operations.Count < NumberOperations
            Operations.AddRange(operators)
        End While
        While Operations.Count > NumberOperations
            Operations.RemoveAt(Operations.Count - 1)
        End While
        Return operations
    End Function

    Private Function NextRandomOperation() As String
        Static R As New Random
        If Operations.Count > 0 Then
            Dim index As Integer = R.Next(Operations.Count)
            Dim operation As String = Operations(index)
            Operations.RemoveAt(index)
            Return operation
        End If
        Return ""
    End Function

End Class

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How can I randomly choose a maths operator and ask recurring maths questions with it?


Tag : python , By : Ben
Date : March 29 2020, 07:55 AM
hope this fix your issue There is a function in Python called eval() that evaluates strings which contain mathematical expressions.
import random

ops = ['+', '-', '*', '/']
num1 = random.randint(0,12)
num2 = random.randint(0,10)
operation = random.choice(ops)

print(num1)
print(num2)
print(operation)

maths = eval(str(num1) + operation + str(num2))

print(maths)

Generating Maths quiz by JQuery


Tag : javascript , By : toma
Date : March 29 2020, 07:55 AM
This might help you I am tasked to edit an external javascript file for a basic Maths quiz for my schoolwork (not allowed to touch the html and the css). I'm very new to programming, and have attempted the question, but it doesn't work. I need some help here, so thanks in advance. , This is the complete substitute for your javascript code.
$(document).ready(function(){
    $('input[type="button"]').click(function(){
            //alert box feedback before generating random numbers
        var num1=parseInt($("#number1").text());
        var num2=parseInt($("#number2").text());
        var total = num1 + num2;
        var answer = parseInt($("input[type='text']").val());

        if ($("input[type='text']").val() === '') {
            alert("You have not key in any answer");
        } else if (answer === total) {
            alert("You have key in the right answer");
        } else {
            alert("You have key in the wrong answer");
        }

        //generate a random number range 1 to 9 for number 1 after clicking alert box using callback function
        $("#number1").innerHTML =
        Math.floor(Math.random() * 10);

        //generate a random number range 1 to 9 for number 2 after clicking alert box using callback function
        $("#number2").innerHTML =
        Math.floor(Math.random() * 10);
    });
});

VB - Maths Quiz Check Answer


Tag : vb.net , By : Gilmar Souza Jr.
Date : March 29 2020, 07:55 AM
around this issue I am currently doing a project and am trying to make my own maths quiz. Basically, I have 3 labels and a textbox. In the first and third label a number is randomly generated. In the second label, a mathematical operator is selected (either +, - or รท). In the textbox, the user will input an answer to the equation, which brings me to the question i would like to ask: , Perhaps this will help.
Given these functions:
    Dim dictionary = New Dictionary(Of String, Func(Of Double, Double, Double))() _
        From _
        { _
            {"+", Function(x, y) x + y}, _
            {"-", Function(x, y) x - y}, _
            {"*", Function(x, y) x * y}, _
            {"/", Function(x, y) x / y} _
        }

    Dim process As Func(Of String, String, String, Double) = _
        Function(op, x, y) _
            dictionary(op)(Double.Parse(x), Double.Parse(y))
    Dim operator = TextBox1.Text ' "+"
    Dim num1 = TextBox2.Text ' "5"
    Dim num2 = TextBox3.Text ' "4"
    Dim result = process(operator, num1, num2) ' 9

Maths Quiz Task Python


Tag : python , By : desmiserables
Date : March 29 2020, 07:55 AM
will be helpful for those in need You're close... you just need to move the positioning of your loop a little bit so that it catches the actual asking of the question.
As it stands now, you're only looping over the part where you generate the questions.
from random import randint 

while True:
    correct = 0

    userrange = int(input("How many questions would you like?\n"))

    difficulty = input("Choose your difficulty: beginner, intermediate or advanced?\n")

    if difficulty == "beginner":
            no = 10
    if difficulty == "intermediate":
            no = 25
    if difficulty == "advanced":
            no = 100

    qtype = input("Would you like to do addition, subtraction or multiplication?\n")    

    for i in range(userrange):  # Move the loop to start here, instead of under each if / elif
        n1 = randint(1, no)  # We can go ahead and generate our random numbers here also
        n2 = randint(1, no)
        if qtype == "addition":
            prod = n1 + n2
            lo = "plus"
        elif qtype == "subtraction":
            prod = n1 - n2
            lo = "minus"
        elif qtype == "multiplication":
            prod = n1 * n2
            lo = "times"


        ans = int(input("What's %d %s %d?"  % (n1 ,lo ,n2)))  # We also need to move the question into the loop, so that it is asked each time
        if ans == prod:
            print ("That's right -- well done.\n")
            correct = correct + 1
        else:
            print ("No, I'm afraid the answer is %d.\n" % prod)



    print ("\nI asked you %d questions.  You got %d of them right." %(userrange, correct))
    if correct >= (userrange%3)*2:
        print ("Well done!")
    elif (userrange%3) < correct < (userrange%3)*2:
        print ("You need more practice")
    else:
        print ("Please ask your maths teacher for help!")


    try_again = int(input("\nPress 1 to try again, press 0 to exit.\n "))
    if try_again == 0:
        break

PHP simple maths quiz program


Tag : php , By : Kiltec
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Date convert error show on combobox "Unable to cast object of type 'System.String' to type 'System.IFormatProvider'
  • How to pass values from textbox to crystal report
  • Vb.net Outlook pick first in sent mail folder getfirst from last weeks items instead of the first item
  • Move rows from DataTableA to DataTableB with update to Datarow
  • Code Spewing Numbers, where it only should be binary
  • NPOI Read and write removes format control of the checkbox
  • How to send STX and ETX over sockets
  • Integrate an API into a vb.net service app to execute
  • How to change crystal report row forecolor base on dates
  • Entity with Winforms / bindingsource - can't save user input from controls
  • how to print hidden and visible content on a panel when scroll using vb.net
  • NIST p256 Point Decompression: Finding Y-Coordinate For Base Point
  • VB.NET | Get current user profile folder
  • How to create a folder and a file in my project root directory
  • Read connection string saved in file
  • How to call a sub within anohter sub that is on a different form. VB.NET
  • How can I create a generic class that only works for classes that support certain interface?
  • How can hide form after form load?
  • Convert string to color VB.NET
  • Method not returning a value [VB.NET]
  • Testing if I have full read/write access to a file in VB .NET 4.5 before processing it
  • Using Linq order by an object's property Vb.Net
  • Multithreading on multiple datatables
  • Deal with Null object references through Interfaces
  • Constantly resetting minimum and maximum vales within a loop vb.net
  • creating VB.NET DLL without admin rights
  • VB.net - printing picture box
  • How can get array random from another array string?
  • Is there a way to do something similar to IIF(condition, trueValue, falseValue) within a linq statement?
  • Creating Sub Reports Total And Grand Total In Crystal Report
  • Search table with x number of arguments
  • how to refresh my datagridview after I add new data
  • How to get Motherboard name in VB.net?
  • Loop Through LINQ Results
  • Page is empty after adding OnRowDataBound to a GridView
  • VB Rename Folder to DATE_TIME
  • How do I remove this GoTo?
  • Vb.net, Instantiating a class
  • Simple VB.Net text base communication server
  • How do I check for an empty object in VB?
  • Display image in DataGridView not working properly
  • Display Table Records from AS400 to Visual Basic
  • Referencing resource images dynamically
  • Set DateTime in App.Config
  • Visual Basic add to timestamp date
  • Catch event from Main Form
  • Expression Lambda to order fields with null value
  • Change UI from another class created in a thread in vb.net
  • Hangman Game: How To Make The Program Know I Wrote The Correct Word?
  • Calling a background workers "RunWorkerAsync" within another background workers "RunWorkerCompleted"
  • how to get the index of the treeview child node?
  • DevExpress CheckButton not toggeling?
  • A Function to evaluate an integer as a decimal
  • How to modify .INI file with using sharpconfig?
  • I want to get 3 highest values in output when i execute query in vb 2010
  • How to use GroupFormatter with ObjectListView control
  • DevExpress Add items to ComboBox at run time
  • GetManifestResourceStream in module
  • Save and open vbs script programmatically
  • Option Strict On, set Focus of unknown object type
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com