samedi 16 septembre 2023

Cannot find solution to a randomly generated equation

im fairly new to python. trying to create a math quiz game as an assignment. i tried saving random int to a variable but that would return same value. i switched to creating a function, now im able to print a random equation but i cant know what i printed so i cant solve it to compare user answer.

This is my current code

import random

score = 0
symbol = ['+', '-', '*', '/', '^']
def num():
    print(int(random.randint(1, 25)), end = '')
def sym():
    print(random.choice(symbol), end = '')
def eq():
    (num(), sym(), num())
eq()
def sol():
    #???

edit: using return value now, dont know what the error is

import random

score = 0
symbol = ['+', '-', '*', '/', '^']
def num():
    print(int(random.randint(1, 25)), end = '')
    return(random.randint)
def sym():
    print(random.choice(symbol), end = '')
def eq():
    ques = (num(), sym(), num())
    return ques
equation = eq()
print(equation)



Aucun commentaire:

Enregistrer un commentaire